/** ***********************************************************************************
* @file         vehicle_data_process.c
* @brief        车机数据解析处理
* @details      主要用来处理和MCU 数据解析，处理从车机传输的数据
* @author       
* @date         2021/01/30
* @copyright    北京高知科技有限公司    
* @version      V1.0
* @attention    无
**************************************************************************************/
#define OSI_LOG_TAG OSI_MAKE_LOG_TAG('M','C', 'A', 'R')

#include "fibo_opencpu.h"
#include "national_data_process.h"
#include "com_lib.h"
#include "n808_app.h"
#include "net_port.h"
#include "algorithm.h"
#include "mon_task.h"
#include "power_task.h"
#include "bluetooth_app.h"
#include "fota.h"
#include "files.h"
#include "flash_dev.h"
#include "gsen_task.h"
#include "mangpatio.h"
#include "AES.h"
#include "vehicle_data_process.h"

#define VEH_MAN_NAME    "VEH_MAN_TASK"
#define VEH_CTRL_NAME    "VEH_CTRL_TASK"
#define VEH_OTA_NAME    "VEH_OTA_TASK"


static uint16_t mcuserialnum = 0;//本地流水號
uint8_t mcu_version[23]={0},mcu_version_old[23]={0};/*mcu版本号*/
mcu_ota_st_t mcu_ota_st = {0};/*mcu升级状态属性*/
n808_gsen_st_t n808_gsen_st = {0};/*gsen回调的状态*/
mcu_send_pkekey_t mcu_pkekey = {0};
static uint32_t national808_save_time_tick;     /*周期上报时间*/
static uint32_t national808_meter_time_tick;     /*距离上报时间*/
static uint32_t national808_ctlock_time_tick;     /*控锁时间*/
static n808_mcu_recv_buf_typedef mcu_recv_data; /*数据接收底层缓存数据*/
GaozSemaphoreHandle_t   mcu_recv_data_mutex = 0; //接收互斥
GaozSemaphoreHandle_t   vehicle_data_mutex = 0; //更新互斥
GaozSemaphoreHandle_t 	vehicle_ota_sem = 0; /*mcu ota信号量*/
GaozSemaphoreHandle_t   upgradeid_mutex = 0; //串口更新ID
n808_vehicle_data_t vehicle_data={0},vehicle_data_old={0};/*车身数据*/
sz_ext_status_struct_typedef sz_ext_status_struct;
vehicle_new_info_0504_25_struct_typedef vehicle_new_info_0504_25_info;
mcu_response_e mcu_response;     /*应答的方式*/
mcu_send_data_e mcu_send_data;   /*发送数据的状态*/
vehicle_ctrl_run_state_e vehiclect_runing_st;/*任务允许状态*/
can_work_state_e can_work_st=CAN_WORK_ST_INIT;    /* ACC的状态*/
//gsen_bmi160_body_state_e gsen_oldst=GSEN_ATT_ST_INIT;
mcu_send_data_st_t mcu_send_data_st; /*mcu交互过程中属性值*/
GaozQueueHandle_t mcu_send_res_queue; /*发送数据应答消息队列*/
GaozQueueHandle_t ota_mcu_notify_queue; /*通知消息队列*/
GaozQueueHandle_t ota_mcu_request_queue; /*請求消息队列*/
static uint8_t sys_power_old = 0,veh_power_old = 0;/*系统电源*/
volatile uint32_t port_counter = 0; 
static uint8_t print_mcu_flag = 0;
static vehicle_authentication_type_e vehicle_authentication_st;
static vehicle_authentication_type_e vehicle_authentication_mangpatio_st;
static vehicle_engine_start_infor_t vehicle_engine_start_infor;
static vehicle_engine_start_result_t vehicle_engine_start_result;
vehicle_save_data_t vehicle_save_data;
vehicle_save_data_t current_data;

#define vehicledata_mutex_lock()  gaoz_mutex_lock(vehicle_data_mutex)  
#define vehicledata_mutex_unlock()  gaoz_mutex_unlock(vehicle_data_mutex)

sfb_buf_rt_t sfb_handle_808;  /*存储句柄*/
uint32_t sfb_handle_id;  /*操作句柄id*/
static uint32_t min_mile=0,allkilo_mod=0;

static uint8_t vehicle_mcu_save_infor[VEH_MCU_INFOR_SIZE],vehicle_mcu_save_infor_old[VEH_MCU_INFOR_SIZE];
static uint8_t vehicle_mcu_save_size;
vehicle_warmcar_package_data_t vehicle_warmcar_package;
vehicle_warmcar_led_data_t vehicle_warmcar_led_data;
vehicle_warmcar_net_data_t vehicle_warmcar_net_data;
vehicle_fault_code_state_e vehicle_fault_code_state;
vehicle_fault_code_infor_t vehicle_fault_code_infor;
new_vehicle_fault_code_infor_t new_vehicle_fault_code_infor;
vehicle_maintenance_infor_t vehicle_maintenance_infor;
vehicle_maintenance_cfg_t vehicle_maintenance_cfg;
vehicle_bms_infor_t vehicle_bms_infor;

vehicle_seed_infor_t vehicle_seed_infor;
vehicle_key_infor_t  vehicle_key_infor;

vehicle_adas_infor_t vehicle_adas_infor;
vehicle_adas_position_t vehicle_adas_position[VEH_ADAS_POSION_NUM];
static uint8_t  vehicle_rv_power_control;	/*房车电源控制*/
//存储描述
const sfb_setting_t sfb_set_808=
{ 
	SF_SFB_HANDLE_ADDR,
    SF_SAVE_DATA_ADDR,
    SPI_FLASH_MIN_SECTOR,
    SF_SAVE_DATA_FlAG_SECTORS,
    UNIT_FLASH_DATA_LEN,
    SPI_FLASH_MIN_SECTOR / UNIT_FLASH_DATA_LEN,
};

static void mcu_recv_data_mutex_create( void );
static uint32_t n808_data_to_save( terminal_info_t	*curinf );
static void inc_mcuserialnum(void);
static int msgtranslation_tx(uint8_t *da , uint16_t len);
static void genre_0x1000_Sta(uint8_t *date,uint16_t cmd, uint16_t reserialNum, uint8_t sta);
static uint8_t rcvsplit_parse(uint8_t *pa,uint16_t len,n808_vehicle_data_t *cardata);
static uint8_t parse_vehicledata(uint8_t *da, uint16_t len);
static void parse_mcu_recv_data( uint8_t *da, uint16_t len );
static void  vehicle_data_handle_task( void * pvParameters);
static uint32_t n808_get_updata_meter( system_work_mode_s sys_st, terminal_info_t *curinf, n808_vehicle_data_t *cardata,gnss_info_struct *info);
static uint32_t sendto_mcu_info(uint16_t msID,uint8_t *devID,uint8_t *date,uint16_t len);
static uint32_t vehicle_portstatus_get( void *pv);
static uint8_t warmcarbms_parse(uint8_t *pa,uint16_t len, vehicle_warmcar_package_data_t *cardata);
static uint8_t warmcarled_parse(uint8_t *pa,uint16_t len, vehicle_warmcar_led_data_t *cardata);
static void warmcarled_heart_state_set(uint8_t st );
static uint16_t warmcarled_net_data_read( uint8_t *pa );
static void warmcarled_net_data_clear( void );
static void vehicle_authentication_time_detection( void );
static void vehicle_adas_position_read( void );
static void vehicle_save_mcu_data_infor_init( void );
static void vehicle_save_mcu_data_infor_send( void );
static void print_save_mcu_data( void );
/** ****************************************************************************
* @remarks       uint32_t n808_cle_save_data(void)
* @brief         清除缓存的数据
* @param[in]     无
* @param[out]    无
* @return        pdPASS 成功 ，pdFAIL 失败
* @attention     
*******************************************************************************/
uint32_t n808_cle_save_data(void)
{
	uint32_t ret = pdFAIL;

	gaoz_save_data_close(sfb_handle_id);
	ret = gaoz_save_data_open( &sfb_handle_808 ,&sfb_set_808 ,&sfb_handle_id );
	if( ret == pdPASS )
	{
		gaoz_log_debug_printf(INFOR_MODE,"mcar","gaoz_save_data_open ok[%d]\n", sfb_handle_id);
	} 
   
   return ret;
}
/** ****************************************************************************
* @remarks       uint32_t gzlable_operateid(uint8_t cmd,uint8_t *data,uint16_t len)
* @brief         工装标签通信交互
* @param[in]     cmd,result
* @param[out]    无
* @return        pdPASS 成功 ，pdFAIL 失败
* @attention     
*******************************************************************************/
uint32_t gzlable_operateid(uint8_t cmd,uint8_t *data,uint16_t len)
{
	uint32_t ret = pdFAIL;
	uint8_t tpmda[256];

	tpmda[0] = cmd;
	if(len <= 1)
	{
		tpmda[1] = len;
		ret = sendto_mcu_info(0x2020,(uint8_t *)TERM_ID,tpmda,2);
	}
	else
	{
		if(len > 256)
		{
			len = 256;
		}
		memcpy(&tpmda[1],data,len);
		ret = sendto_mcu_info(0x2020,(uint8_t *)TERM_ID,tpmda,len+1);
	}
	
	if( ret == pdPASS )
	{
		gaoz_log_debug_printf(INFOR_MODE,"mcar","gzlable_operateid ok[]\n" );
	} 

	return ret;
}
/** ****************************************************************************
* @remarks       void mcu_ota_cle_overnum(void)
* @brief         清楚升级标记
* @param[in]     无
* @param[out]    无
* @return       无 
* @attention     
*******************************************************************************/
void mcu_ota_cle_overnum(void)
{
	mcu_ota_st.mcu_ota_overnum = 0;
	mcu_ota_st.mcu_ota_st = MCU_OTA_INIT;
}
/** ****************************************************************************
* @remarks      uint8_t *get_mcuversion(void)
* @brief         获取mcu版本
* @param[in]     无
* @param[out]    无
* @return    	缓存区指针  
* @attention     
*******************************************************************************/
uint8_t *get_mcuversion(void)
{
	return mcu_version;
}
/** ****************************************************************************
* @remarks       void mcu_ota_set_overnum(void)
* @brief         设置升级次數
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     
*******************************************************************************/
void mcu_ota_set_overnum(void)
{
	if(mcu_ota_st.mcu_ota_overnum < 100)
	{
		mcu_ota_st.mcu_ota_overnum++;
	}
}
/** ****************************************************************************
* @remarks       void mcu_ota_set_status(void)
* @brief         设置升级过程状态
* @param[in]     无
* @param[out]    无
* @return        
* @attention     
*******************************************************************************/
void mcu_ota_set_status(void)
{
	mcu_ota_st.mcu_ota_st = MCU_OTA_REQUEST;
}
/** ****************************************************************************
* @remarks      uint8_t get_vehicleAcc_st(void)
* @brief         获取点火状态;
* @param[in]     无
* @param[out]    无
* @return    	08点火 00熄火 
* @attention     
*******************************************************************************/
uint8_t get_vehicleAcc_st(void)
{
	if( (vehicle_data.Ignition_status&0x08) == 0x08 )
	{
		return 1;
	}

	return 0;
}

/** ****************************************************************************
* @remarks      uint8_t get_vehicleLock_st(void)
* @brief        获取锁状态 
* @param[in]     无
* @param[out]    无
* @return    	01解锁 00上锁 
* @attention     
*******************************************************************************/
uint8_t get_vehicleLock_st(void)
{
	return (vehicle_data.lock&0x01);
}
/** ****************************************************************************
* @remarks       vehicle_ctrl_run_state_e vehiclect_runing_state_get( void )
* @brief         设置运行状态
* @param[in]     无
* @param[out]    无
* @return        运行状态
* @attention     
*******************************************************************************/
vehicle_ctrl_run_state_e vehiclect_runing_state_get( void )
{
	return vehiclect_runing_st;
}

/** ****************************************************************************
* @remarks       void vehiclect_runing_state_set( vehicle_ctrl_run_state_e  state )
* @brief         获取运行状态
* @param[in]     state 运行状态
* @param[out]    无
* @return        无
* @attention     
*******************************************************************************/
void vehiclect_runing_state_set( vehicle_ctrl_run_state_e  state )
{
	vehiclect_runing_st = state;
}
/** ****************************************************************************
* @remarks       static  can_work_st_set( gsen_bmi160_work_state_e st )
* @brief         设置ACC状态
* @param[in]     无
* @param[out]    无
* @return       
* @attention     无
*******************************************************************************/
/*
static void can_work_st_set( can_work_state_e st )
{
    can_work_st = st;
}
*/
/** ****************************************************************************
* @remarks       can_work_state_e can_work_st_get( void )
* @brief         获取ACC工作状态
* @param[in]     无
* @param[out]    无
* @return        
* @attention     无
*******************************************************************************/
/*
can_work_state_e can_work_st_get( void )
{
    return can_work_st;
}
*/
/** ****************************************************************************
* @remarks       void mcu_recv_data_mutex_create( void )
* @brief         资源创建初始化
* @param[in]     
* @param[out]    无
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
static void mcu_recv_data_mutex_create( void )
{
    /*创建任务互斥体*/
    mcu_recv_data_mutex = gaoz_mutex_create();
    if( mcu_recv_data_mutex == 0 )
    {
        while(1); /*创建失败*/
    }
}
/** ****************************************************************************
* @remarks       static void mcu_send_res_queue_create( void )
* @brief         接收数据队列消息初始化
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void mcu_send_res_queue_create( void )
{
    mcu_send_res_queue = gaoz_queue_create( MCU_ACK_QUEUE_MAX_NUM, sizeof( mcu_res_msg_t ) );
    if( mcu_send_res_queue == 0 )
    {
        while( 1 );
    }
}
/** ****************************************************************************
* @remarks       static uint32_t mcu_send_res_queue_get( national_net_res_msg_t *res_msg , uint32_t delay_time )
* @brief         获取响应消息队列
* @param[in]     *res_msg 获取的数据地址
* @param[in]     delay_time 等待的时间
* @param[out]    无
* @return        pdPASS 接收数据成功 ，pdFAIL 接收数据失败
* @attention     无
*******************************************************************************/
static uint32_t mcu_send_res_queue_get( mcu_res_msg_t *res_msg , uint32_t delay_time )
{
    if( mcu_send_res_queue == 0 )
    {
        mcu_send_res_queue_create();
    }
    if(gaoz_queue_get( mcu_send_res_queue, res_msg, delay_time )  >= 0 ) //
    {
        return pdPASS;
    }
  
    return pdFAIL;
}

/** ****************************************************************************
* @remarks       static uint8_t national_net_res_queue_put( national_net_res_msg_t *res_msg )
* @brief         发送响应消息队列
* @param[in]     *res_msg 发送的数据地址
* @param[out]    无
* @return        1 发送数据成功 ，0 发送数据失败
* @attention     无
*******************************************************************************/
static uint8_t mcu_send_res_queue_put( mcu_res_msg_t *res_msg )
{
    if( gaoz_queue_put( mcu_send_res_queue, ( void * )res_msg, 1000 ) == 0 )
    {
        return 1;
    }
	else
	{
		return 0;
	}
}

/** ****************************************************************************
* @remarks       static void vehicle_ota_sem_create(void)
* @brief         创建ota接收信号量
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void vehicle_ota_sem_create(void)
{
    vehicle_ota_sem = gaoz_sem_new(0);
    if( vehicle_ota_sem == 0 )
    {
        while( 1 ); /*创建失败*/
    }
}

/** ****************************************************************************
* @remarks       static uint8_t vehicle_ota_sem_get(void)
* @brief         接收信号量
* @param[in]     无
* @param[out]    无
* @return        1 接收到数据 ， 0 未接收到数据，超时
* @attention     阻塞状态 时间2s
*******************************************************************************/
static uint8_t vehicle_ota_sem_get(void)
{
    if( gaoz_sem_try_wait( vehicle_ota_sem, 2000 ) == true ) //等待回应信号量
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

/** ****************************************************************************
* @remarks       static uint8_t vehicle_ota_sem_set(void)
* @brief         发送信号量
* @param[in]     无
* @param[out]    无
* @return       无
* @attention     无
*******************************************************************************/
void vehicle_ota_sem_set(void)
{
    gaoz_sem_signal( vehicle_ota_sem ); /*发送信号量，通知任务*/
}
/** ****************************************************************************
* @remarks       static void ota_mcu_notify_queue_create( void )
* @brief         通知升级消息初始化
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void ota_mcu_notify_queue_create( void )
{
    ota_mcu_notify_queue = gaoz_queue_create( MCU_ACK_QUEUE_MAX_NUM, sizeof( ota_mcu_notify_t ) );
    if( ota_mcu_notify_queue == 0 )
    {
        while( 1 );
    }
}
/** ****************************************************************************
* @remarks       static uint32_t ota_mcu_notify_queue_get( ota_mcu_notify_t *res_msg , uint32_t delay_time )
* @brief         获取通知响应消息
* @param[in]     *res_msg 获取的数据地址
* @param[in]     delay_time 等待的时间
* @param[out]    无
* @return        pdPASS 接收数据成功 ，pdFAIL 接收数据失败
* @attention     无
*******************************************************************************/
uint32_t ota_mcu_notify_queue_get( ota_mcu_notify_t *res_msg , uint32_t delay_time )
{
    if( ota_mcu_notify_queue == 0 )
    {
        ota_mcu_notify_queue_create();
    }
    if(gaoz_queue_get( ota_mcu_notify_queue, res_msg, delay_time )  >= 0 ) //
    {
        return pdPASS;
    }
  
    return pdFAIL;
}

/** ****************************************************************************
* @remarks       static uint8_t ota_mcu_notify_queue_put( ota_mcu_notify_t *res_msg )
* @brief         发送通知消息
* @param[in]     *res_msg 发送的数据地址
* @param[out]    无
* @return        1 发送数据成功 ，0 发送数据失败
* @attention     无
*******************************************************************************/
static uint8_t ota_mcu_notify_queue_put( ota_mcu_notify_t *res_msg )
{
    if( gaoz_queue_put( ota_mcu_notify_queue, ( void * )res_msg, 1000 ) == 0 )
    {
        return 1;
    }

	return 0;
}

/** ****************************************************************************
* @remarks       static void ota_mcu_request_queue_create( void )
* @brief         mcu请求消息队列
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void ota_mcu_request_queue_create( void )
{
    ota_mcu_request_queue = gaoz_queue_create( MCU_ACK_QUEUE_MAX_NUM, sizeof( ota_mcu_request_t ) );
    if( ota_mcu_request_queue == 0 )
    {
        while( 1 );
    }
}
/** ****************************************************************************
* @remarks       static uint32_t ota_mcu_request_queue_get( ota_mcu_request_t *res_msg , uint32_t delay_time )
* @brief         获取请求消息队列
* @param[in]     *res_msg 获取的数据地址
* @param[in]     delay_time 等待的时间
* @param[out]    无
* @return        pdPASS 接收数据成功 ，pdFAIL 接收数据失败
* @attention     无
*******************************************************************************/
static uint32_t ota_mcu_request_queue_get( ota_mcu_request_t *res_msg , uint32_t delay_time )
{
    if( ota_mcu_request_queue == 0 )
    {
        ota_mcu_request_queue_create();
    }
    if(gaoz_queue_get( ota_mcu_request_queue, res_msg, delay_time )  == 0 ) //
    {
        return pdPASS;
    }
  
    return pdFAIL;
}

/** ****************************************************************************
* @remarks        uint8_t ota_mcu_request_queue_put( ota_mcu_notify_t *res_msg )
* @brief         发送请求消息队列
* @param[in]     *res_msg 发送的数据地址
* @param[out]    无
* @return        1 发送数据成功 ，0 发送数据失败
* @attention     无
*******************************************************************************/
uint8_t ota_mcu_request_queue_put( ota_mcu_request_t *res_msg )
{
    if( gaoz_queue_put( ota_mcu_request_queue, ( void * )res_msg, 1000 ) == 0 )
    {
        return 1;
    }

	return 0;
}
/** ****************************************************************************
* @remarks       uint32_t ota_mcu_notify(uint32_t date)
* @brief         通知升级
* @param[in]     date长度
* @param[out]    无
* @return        1 发送数据成功 ，0 发送数据失败
* @attention     无
*******************************************************************************/
uint32_t ota_mcu_notify(uint32_t date)
{
    uint32_t ret = pdFAIL;
    ota_mcu_notify_t notify_msg;
    notify_msg.upgrade_flag = 0x01;
    notify_msg.upgrade_total = date; 
    ret = ota_mcu_notify_queue_put(&notify_msg);
    if(ret < 1)
    {
       gaoz_log_debug_printf(INFOR_MODE,"mcar","ota_mcu_notify_queue_put fail \r\n"); 
    }
	else
	{
		ret = pdPASS;
	}
    return ret;
}
/** ****************************************************************************
* @remarks      static uint32_t n808_get_updata_meter( system_work_mode_s sys_st, terminal_info_t *curinf, n808_vehicle_data_t *cardata,gnss_info_struct *info)
* @brief         距离统计,统计运行和休眠模式下上报距离间隔
* @param[in]     sys_st系统状态 *curinf参数表信息 *cardata车身数据 *info gps数据
* @param[out]    无
* @return         pdPASS 数据发送失败 pdFAIL 数据发送成功
* @attention     
*******************************************************************************/
static uint32_t n808_get_updata_meter( system_work_mode_s sys_st, terminal_info_t *curinf, n808_vehicle_data_t *cardata,gnss_info_struct *info)
{
	uint32_t ret = pdFAIL;
	uint32_t currentspeed=0;

	if(curinf == NULL)
	{
		return ret;
	}

	if(sys_st == SYS_ST_RUN)
	{
		if(info == 0)
		{
			currentspeed = cardata->speed*100;
			min_mile += (allkilo_mod+currentspeed)/3600;
			allkilo_mod = (allkilo_mod+currentspeed)%3600;
			if(min_mile > hex4CombineOne(curinf->workReportMaxMeter))
			{
				gaoz_log_debug_printf(INFOR_MODE,"mcar","<<->>min_mile = %d,TagInf.workReportMaxMeter=%d\r\n",min_mile,hex4CombineOne(curinf->workReportMaxMeter));
				min_mile = 0;
				ret = pdPASS;
			}
		}
		else
		{
			currentspeed = info->gnss_position_info.speed *100;
			min_mile += (allkilo_mod+currentspeed)/3600;
			allkilo_mod = (allkilo_mod+currentspeed)%3600;
			if(min_mile > hex4CombineOne(curinf->workReportMaxMeter))
			{
				gaoz_log_debug_printf(INFOR_MODE,"mcar","<<->>min_mile = %d,TagInf.workReportMaxMeter=%d\r\n",min_mile,hex4CombineOne(curinf->workReportMaxMeter));
				min_mile = 0;
				ret = pdPASS;
			}
		}
	}
	else if(sys_st == SYS_ST_WAKE)
	{
		if(info == 0)
		{
			currentspeed = cardata->speed*100;
			min_mile += (allkilo_mod+currentspeed)/3600;
			allkilo_mod = (allkilo_mod+currentspeed)%3600;
			if(min_mile > hex4CombineOne(curinf->idleReportMaxMeter))
			{
				gaoz_log_debug_printf(INFOR_MODE,"mcar","<<->>min_mile = %d,TagInf.idleReportMaxMeter=%d\r\n",min_mile,hex4CombineOne(curinf->idleReportMaxMeter));
				min_mile = 0;
				ret = pdPASS;
			}
		}
		else
		{
			currentspeed = info->gnss_position_info.speed *100;
			min_mile += (allkilo_mod+currentspeed)/3600;
			allkilo_mod = (allkilo_mod+currentspeed)%3600;
			if(min_mile > hex4CombineOne(curinf->idleReportMaxMeter))
			{
				gaoz_log_debug_printf(INFOR_MODE,"mcar","<<->>min_mile = %d,TagInf.idleReportMaxMeter=%d\r\n",min_mile,hex4CombineOne(curinf->idleReportMaxMeter));
				min_mile = 0;
				ret = pdPASS;
			}
		}
	}
	

	return ret;
}

uint32_t make_vehicle_infor(void)
{ 
	uint32_t ret = pdPASS;

#if (OS_HISTORY_VEHICLE_INFO_REPORT == 1)	
	uint8_t txbuf[256]={0};
    int txbuflen=0;	 
	memset(txbuf,0,sizeof(txbuf));
	txbuflen = positioninfo(0,txbuf);
	ret = gaoz_save_data_write( sfb_handle_id , txbuf , txbuflen );
	if( ret == pdPASS )
	{
		gaoz_log_debug_printf(INFOR_MODE,"mcar","gaoz_save_data_write suc\r\n",0);	
	}
	else
	{
		gaoz_log_debug_printf(INFOR_MODE,"mcar","gaoz_save_data_write SYS_ST_RUN fail,\r\n");	
		log_debug_printf(ERROR_MODE,VEH_MAN_NAME ,"[%s]gaoz_save_data_write SYS_ST_RUN fail\r\n",sys_err_infor_pointer_get( 54 ));	
	}
#else
	vehicle_info_report_semaphore_put(); 
#endif
	return ret;
}

/** ****************************************************************************
* @remarks       static uint32_t n808_data_to_save( terminal_info_t	*curinf )
* @brief         808數據存儲功能
* @param[in]     *curinf终端参数
* @param[out]    无
* @return        pdPASS 数据发送失败 pdFAIL 数据发送成功
* @attention    
*******************************************************************************/
static uint32_t n808_data_to_save( terminal_info_t	*curinf )
{
    uint32_t ret = pdFAIL;
	uint8_t txbuf[128]={0};
    int txbuflen=0;
	static uint8_t wake_trial_time = 0; 
    system_work_mode_s sys_st;
	gnss_info_struct gnss_info;
    sys_st = gaoz_sys_work_mode_get();
	gaoz_gnss_info_now_get( &gnss_info );

	if((hex4CombineOne(curinf->workReportMaxTime) == 0) || 
		(hex4CombineOne(curinf->idleReportMaxTime) == 0) || 
			(memcmp(curinf->ManageID,"\x0\x0\x0\x0\x0\x0",6) == 0))
	{
		national808_save_time_tick = gaoz_get_systick(); /*获取当前最新的系统时钟*/   
		national808_meter_time_tick = gaoz_get_systick(); 
		return ret;
	}
    
	if( sys_st == SYS_ST_RUN )
    {
		wakeup_source_set( POWER_INIT );
		mangpatio_sleep_wakeup_state_set( SLEEP_WAKEUP_INIT );
		if( pdPASS == sys_timestamp_delay(( uint32_t * )&national808_save_time_tick, hex4CombineOne(curinf->workReportMaxTime) * GAOZ_TICK_PERIOD_S) )
		{ 
			make_vehicle_infor();

			national808_meter_time_tick = gaoz_get_systick();
			min_mile = 0; 
		}
		else
		{
			if( pdPASS == sys_timestamp_delay(( uint32_t * )&national808_meter_time_tick,  1*GAOZ_TICK_PERIOD_S) )
			{
				if(pdPASS  == n808_get_updata_meter(SYS_ST_RUN, curinf,&vehicle_data,0))
				{ 
					make_vehicle_infor();

					national808_save_time_tick = gaoz_get_systick(); /*获取当前最新的系统时钟*/   
				}
			}
		}
    }
	else if(sys_st == SYS_ST_WAKE)
	{
		if(power_man_wakeup_source_get(POWER_TIME) == pdPASS)
		{
			gaoz_power_man_wakeup_task_num_run(); 
			
			make_vehicle_infor();

			wakeup_source_set( POWER_TIME );						/*向主平台发送TIME休眠唤醒*/
			mangpatio_sleep_wakeup_state_set( SLEEP_STATE_TIME );	/*向辅助平台发送TIME休眠唤醒*/
			gaoz_power_man_wakeup_task_num_stop();
		}
		else if((power_man_wakeup_source_get(POWER_RTC) == pdPASS))
		{ 
			gaoz_power_man_wakeup_task_num_run(); 
			wakeup_source_set( POWER_RTC );
			mangpatio_sleep_wakeup_state_set( SLEEP_STATE_RTC );
			gaoz_power_man_wakeup_task_num_stop();

		}
		// else if((power_man_wakeup_source_get(POWER_CAN) == pdPASS))
		// { 
		// 	gaoz_power_man_wakeup_task_num_run(); 
		// 	wakeup_source_set( POWER_RTC ); 
		// 	gaoz_power_man_wakeup_task_num_stop();
 		// }
		
		if( ++wake_trial_time > 10 )
		{
			wake_trial_time = 0;
			if(pdPASS  == n808_get_updata_meter(SYS_ST_WAKE, curinf,0,&gnss_info))
			{ 
				make_vehicle_infor();
			}
		}
	}

    return ret;
}
/** ****************************************************************************
* @remarks       static uint32_t print_to_mcu( terminal_info_t	*curinf )
* @brief         打印所需数据
* @param[in]     *curinf终端参数
* @param[out]    无
* @return        pdPASS 数据发送失败 pdFAIL 数据发送成功
* @attention    
*******************************************************************************/
static uint32_t print_to_mcu( terminal_info_t	*curinf )
{
    uint32_t ret = pdFAIL;
	uint8_t txbuf[128]={0};
	vehicle_ctrl_run_state_e run_st;
	static uint8_t pricnt = 0,carid[6] = {0};
	run_st = vehiclect_runing_state_get();
	uint8_t ccid[20]={0};

	if( (strlen((char *)curinf->ManageID) == 0) )
	{
		return ret;
	}

	if(memcmp(carid,curinf->ManageID,6) != 0)
	{
		memcpy(carid,curinf->ManageID,6);
		print_mcu_flag = 0;
		pricnt = 0;
	}

	if((print_mcu_flag == 0) && (pricnt < 3))
	{

		net_module_run_state_get( MOD_CCID, (uint8_t *)ccid);

		if(run_st == CARCTL_RUNING_INIT)
		{
			if(strlen((char *)ccid) != 0)
			{
				memcpy(txbuf,curinf->ManageID,6);
				memcpy(&txbuf[6],ccid,20);
				ret = sendto_mcu_info(0x10A7,(uint8_t *)TERM_ID,txbuf,26);
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 10A7: %d\r\n",ret);
				if(ret == pdPASS)
				{

				}
				pricnt++;
			}
		}
	}

    return ret;
}
/** ****************************************************************************
* @remarks       static void mcu_recv_state_cb( void * pv)
* @brief         底层状态回调函数
* @param[in]     * pv 参数输入
* @param[out]    无
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
static void mcu_recv_state_cb(uint8_t sta)
{
	uint8_t	mcu_recv_st;

	mcu_recv_st = (uint8_t )sta;
	//gaoz_log_debug_printf(DEBUG_MODE,"mcar","mcu_recv_state:%d\r\n",mcu_recv_st);	
	switch(mcu_recv_st)
	{
		case TASK_MODE_INIT:
			
			break;
		case TASK_RUN_MODE:
			
			break;
		case TASK_SLEEP_MODE:
			if(hex4CombineOne(taginf.idleReportMaxTime) != 0)
			{
				gaoz_system_wakeup_rtc_time_set(RTC_VEH,hex4CombineOne(taginf.idleReportMaxTime));
			}
			//gaoz_log_debug_printf(INFOR_MODE,"mcar","sleep gaoz_system_wakeup_rtc_time_set : %d\r\n",hex4CombineOne(taginf.idleReportMaxTime));
			break;
		case TASK_STOP_MODE:

			break;
		default:
			break;
	}

}

/** ****************************************************************************
* @remarks       static void inc_mcuserialnum(void)
* @brief         增加流水号  
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     
*******************************************************************************/
static void inc_mcuserialnum(void)
{
	mcuserialnum++;
	if (mcuserialnum > 0x8000)
	{
        mcuserialnum = 1;
	}
}

/** ****************************************************************************
* @remarks       static int msgtranslation_tx(uint8_t *da , uint16_t len)
* @brief         转译发送消息 
* @param[in]      *da缓存区 ,len长度
* @param[out]    无
* @return         pdPASS发送成功 ，  pdFAIL发送失败
* @attention     
*******************************************************************************/
static int msgtranslation_tx(uint8_t *da , uint16_t len)
{
	uint16_t j,txindex;
	uint8_t pdata[1024]={0};
	uint8_t *data = da;
 
	if (len < 1024)
	{
		memcpy(data, da, len);
	}
	else
	{
		return -1;
	}	
	txindex = 0;

	pdata[txindex ++] = 0x7e;

	//消息转译
	for(j = 0;j < len; j ++)
	{
		if(*data == 0x7E)
		{
			pdata[txindex ++] = 0x7D;
			pdata[txindex ++] = 0x02;
		}
		else if(*data == 0x7D)
		{
			pdata[txindex ++] = 0x7D;
			pdata[txindex ++] = 0x01;
		} 
		else 
		{
			pdata[txindex ++] = *data;
		}
		data ++;
	}

	pdata [txindex ++] = 0x7E;
	{	
			#if 0
			uint8_t debug_buf[1024] = {0};
			uint16_t debug_buf_len = 0;
			memset(debug_buf,0,sizeof(debug_buf));
            debug_buf_len = HexToAsciiString(debug_buf,pdata, txindex);
			debug_buf[debug_buf_len] = '\r';
            debug_buf_len++;
            debug_buf[debug_buf_len] = '\n';
            debug_buf_len++;
			gaoz_log_debug_printf(INFOR_MODE,"mcar", "gaoz_mcu_uart_driver_write:%s,%d\r\n",debug_buf, debug_buf_len );
			#endif
	}
    return gaoz_mcu_uart_driver_write(pdata, txindex);//fibo_hal_uart_put(0,pdata, txindex);
}
/** ****************************************************************************
* @remarks       uint32_t sendto_mcu_info(uint8_t *date,uint16_t cmd, uint16_t reserialNum, uint8_t sta)
* @brief         发送给mcu的数据
* @param[in]     msID命令字，devID设备id，date缓存区，len长度
* @param[out]    无
* @return        pdPASS发送成功 ，  pdFAIL发送失败
* @attention     
*******************************************************************************/
static uint32_t sendto_mcu_info(uint16_t msID,uint8_t *devID,uint8_t *date,uint16_t len)
{
	uint8_t storeDa[1024]={0};
	uint16_t idx;
	
	//消息ID
	storeDa[0] = (msID>>8)&0xff;
	storeDa[1] = (msID&0xff);
	
	
	//消息头，共用部分
	idx = 4;
	memcpy(&storeDa[idx], devID, 6);
    idx += 6;
	//序列号
	storeDa[idx++] = mcuserialnum >> 8;
	storeDa[idx++] = (mcuserialnum & 0x00FF);
	inc_mcuserialnum();
	
	//消息体部分 
	if(len != 0)
	{
		memcpy(&storeDa[idx], date, len);
		idx += len;
	}
	//消息体属性
	storeDa[2] = (u8)((idx - 12) >> 8);
	storeDa[3] = (u8)(idx - 12);
	
	storeDa[idx] = get_chk_xor(storeDa, idx);
	idx++;

	//转义处理
	return msgtranslation_tx(storeDa, idx);
}
/** ****************************************************************************
* @remarks       static void genre_0x1000_Sta(uint8_t *date,uint16_t cmd, uint16_t reserialNum, uint8_t sta)
* @brief         通用应答
* @param[in]     date缓存区，cmd命令字  reserialNum应答流水号， sta结果
* @param[out]    无
* @return        无
* @attention     
*******************************************************************************/
static void genre_0x1000_Sta(uint8_t *date,uint16_t cmd, uint16_t reserialNum, uint8_t sta)
{
	uint8_t tmpDa[30];
	
	//消息头，共用部分		
	tmpDa[0] = 0x10;
	tmpDa[1] = 0x00;
	
	//car ID
	memcpy(&tmpDa[4], date, 6);

	//流水号
	tmpDa[10] = (uint8_t)(mcuserialnum >> 8);
	tmpDa[11] = (uint8_t)(mcuserialnum & 0xff);
	inc_mcuserialnum();
	//应答流水号
	tmpDa[12] = (uint8_t)(reserialNum>>8);
	tmpDa[13] = (uint8_t)(reserialNum);

	//应答ID
	tmpDa[14] = (uint8_t)(cmd>>8);
	tmpDa[15] = (uint8_t)(cmd);
	//结果
	tmpDa[16] = sta;
	//属性
	tmpDa[2] = 0;
	tmpDa[3] = 5;
	//校验
	tmpDa[17] = get_chk_xor(tmpDa,17);
	
    msgtranslation_tx(tmpDa,18);	
}
/** ****************************************************************************
* @remarks       void vehicle_data_now_get( n808_vehicle_data_t *cardata )
* @brief         获取車輛数据数据信息
* @param[in]     无
* @param[out]    cardata缓存区
* @return        无
* @attention     无
*******************************************************************************/
void vehicle_data_now_get( n808_vehicle_data_t *cardata )
{
    vehicledata_mutex_lock();
    memcpy(( uint8_t * )cardata, ( uint8_t * )&vehicle_data, sizeof( n808_vehicle_data_t ) );
    vehicledata_mutex_unlock();
}

/** ****************************************************************************
* @remarks       void parseAuth(u8 *da, u16 len,u16 cmd,u16 reserialNum)
* @brief         PC端數據解析，透传数据解析
* @param[in]     *da缓存区  len长度  cmd命令字  reserialNum应答流水号
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void parseAuth(uint8_t *da, uint16_t len,uint16_t cmd,uint16_t reserialNum)
{
	int ret = 0;
	uint16_t termlen = 0;

	char *tmpDa = (char *)fibo_malloc(1024*1);
	if (tmpDa != NULL)
	{
		memset(tmpDa,0,1024*1);
	}

	switch(da[0])
	{
		case 0x01://pid
		{
		
		}
		break;
		case 0x02://devname
		{

		}
		break;
		case 0x03: //devsecret
		{
		
		}
		break;
		case 0x04://CA 
		{
			
		}
		break;
		case 0x05://termid
		{

		}	
		break;	
		case 0x06://unregister
		{

		}	
		break;	

		case 0x10:
			gzlable_print((uint8_t*)tmpDa,&termlen,1);
			ret = gzlable_operateid(0x14,(uint8_t*)tmpDa,termlen);
			if(ret == pdPASS)
			{
				gaoz_log_debug_printf(INFOR_MODE,"mcar","gzlable_print <-- %s,%d",tmpDa,termlen);

			}
			break;

		case 0x11:
		{
			if(gzlable_eraseid() == pdPASS)
			{
				gzlable_operateid(0x15,NULL,0);
			}
			else
			{
				gzlable_operateid(0x15,NULL,1);
			}
		}
		break;
		case 0x12:
		{
			uint8_t tp[10]={0};
			if(chk_valid_bcd_num(&da[3],4) == 1)
			{
				if(len > 3)
				{
					//增加800头
					tp[0] = 0x80;
					tp[1] = 0x0f&((da[3]>>4)&0x0f);
					tp[2] = (((da[3]&0x0f)<<4)&0xf0)|((da[4]>>4)&0x0f);
					tp[3] = (((da[4]&0x0f)<<4)&0xf0)|((da[5]>>4)&0x0f);
					tp[4] = (((da[5]&0x0f)<<4)&0xf0)|((da[6]>>4)&0x0f);
					tp[5] = (((da[6]&0x0f)<<4)&0xf0)&0xf0;
					//memcpy(tp,&da[3],len-3);
					memcpy(tmpDa,&da[3],len-3);
					memcpy(&tmpDa[4],"EDTT",4);
					init_paratable(tp,(uint8_t *)&tmpDa[8],&termlen);
					gaoz_log_debug_printf(INFOR_MODE,"mcar","init_paratable <--%s,%d",tmpDa,termlen+8);
					ret = file_termpara_write(TERMID_FILE,tmpDa,termlen+8);
					if(ret > 8)
					{	
						flash_spi_sector_erase(SF_SYS_PARA_FLAG_ADDR);
						flash_spi_write_data(SF_SYS_PARA_FLAG_ADDR,(uint8_t *)tmpDa,termlen+8);
						fibo_taskSleep(100);	
						flash_spi_sector_erase(SF_SYS_PARA_BACKUP_ADDR);
						flash_spi_write_data(SF_SYS_PARA_BACKUP_ADDR,(uint8_t *)tmpDa,termlen+8);
						if(upgradeid_mutex == 0)
						{
							upgradeid_mutex = gaoz_sem_new(0);
							gaoz_sem_signal( upgradeid_mutex ); /*发送信号量，通知任务*/
							ret = gzlable_operateid(0x13,NULL,0);
							gaoz_log_debug_printf(INFOR_MODE,"mcar","gzlable_operateid(0x13,NULL,0)[%d]",ret);
						}
					}
				}
			}
		}	
		break;
		case 0x13:
		{
			gzlable_print((uint8_t *)tmpDa,&termlen,0);
			ret = gzlable_operateid(0x14,(uint8_t *)tmpDa,termlen);
			if(ret == pdPASS)
			{	
				gaoz_log_debug_printf(INFOR_MODE,"mcar","gzlable_print <--%s,%d",tmpDa,termlen);		
			}	
		}	
		break;
		case 0x14:
		{
			terinf.Mode = 0x10;
		}
		break;
		case 0x15:
		{
			termlen = (da[1]<<8)+da[2];
			if(gzlable_exchangeip(&da[3],termlen) == pdPASS)
			{
				if(gzlable_operateid(0x80,NULL,0) == pdPASS)
				{
					gaoz_sys_abnormal_reset_set( SYS_RESET_APP );//重启
				}
			}
			else
			{
				gzlable_operateid(0x80,NULL,1);
			}
		}
		break;
		default:
			break;
	}

	fibo_free(tmpDa);
}
/** ****************************************************************************
* @remarks       static uint8_t rcvsplit_parse(uint8_t *pa,uint16_t len,n808_vehicle_data_t *cardata)
* @brief         解析車輛数据数据
* @param[in]     *pa缓存区，len长度
* @param[out]   cardata 车身数据
* @return        0成功1失败2错误
* @attention     无
*******************************************************************************/
static uint8_t rcvsplit_parse(uint8_t *pa,uint16_t len,n808_vehicle_data_t *cardata)
{
	uint8_t da[128] = {0};
	uint8_t size = 0;
	uint8_t save_flag = 0;
	uint16_t oil = 0,Electricity = 0,Endurance_mileage = 0;
	
	//uint32_t tp_data = 0;

	if(len > 128)
	{
		return 2;
	}
	memcpy(da,pa,len);

	(*cardata).doors_status = da[0];
	(*cardata).lights_status = da[1];
	(*cardata).win_status = da[4];
	(*cardata).lock = da[5];

	if(da[6] != 0)
	{
		(*cardata).brake_gear = da[6];
	}
	else
	{
		save_flag = 1;
	}

	(*cardata).Ignition_status = da[7];
	(*cardata).Charge_status = da[8];   //
	(*cardata).other_status = da[9];

	(*cardata).speed = hex2CombineOne(&da[20]);
	
	(*cardata).bat_vol = hex4CombineOne(&da[25]);

	if(hex4CombineOne(&da[10]) != 0)
	{
		(*cardata).Odo = hex4CombineOne(&da[10]);
	}
	else
	{
		save_flag = 1;
	}

	oil = hex2CombineOne(&da[14]);
	Electricity = hex2CombineOne(&da[16]);
	Endurance_mileage = hex2CombineOne(&da[18]);	

	if(oil == 0)
	{
		if(Electricity && Endurance_mileage)
		{
			(*cardata).Oil = 0;
		}
	}

	else if(Endurance_mileage == 0) 
	{
		if(oil && Electricity)
		{
			(*cardata).Endurance_mileage  = 0;
		}
	}

	

	if(hex2CombineOne(&da[14]) != 0)
	{
		(*cardata).Oil = hex2CombineOne(&da[14]);		//油量
	}
	if(hex2CombineOne(&da[16]) != 0)
	{
		(*cardata).Electricity = hex2CombineOne(&da[16]);	//油量或者电量百分比
	}
	if(hex2CombineOne(&da[18]) != 0)
	{
		(*cardata).Endurance_mileage = hex2CombineOne(&da[18]);		//续航 KM
	}
	if((hex2CombineOne(&da[14]) == 0) && (hex2CombineOne(&da[16]) == 0))
	{
		save_flag = 1;
	}
	(*cardata).relay_sta = da[53]&0x01;
	/*胎压位置48，4个字节*/
	//tp_data =  hex4CombineOne( &da[48] );
	(*cardata).lf_TP = da[51];//( uint8_t )(( tp_data & 0xFF000000 ) >> 24);	//左前轮胎压值
	(*cardata).rf_TP = da[50];//( uint8_t )(( tp_data & 0x00FF0000 ) >> 16);	//右前轮胎压值
	(*cardata).lr_TP = da[49];//( uint8_t )(( tp_data & 0x0000FF00 ) >> 8);	//左后轮胎压值
	(*cardata).rr_TP = da[48];//( uint8_t )( tp_data & 0x000000FF );			//右后轮胎压值
	/*胎温位置56，4个字节*/
	//tp_data =  hex4CombineOne( &da[56] );
	(*cardata).lf_T = da[59];//( uint8_t )(( tp_data & 0xFF000000 ) >> 24);	//左前轮胎温度
	(*cardata).rf_T = da[58];//( uint8_t )(( tp_data & 0x00FF0000 ) >> 16);	//右前轮胎温度
	(*cardata).lr_T = da[57];//( uint8_t )(( tp_data & 0x0000FF00 ) >> 8);	//左后轮胎温度
	(*cardata).rr_T = da[56];//( uint8_t )( tp_data & 0x000000FF );			//右后轮胎温度
	(*cardata).TPMSRst = da[60];	//胎压标志是否有效
	(*cardata).vehicle_type = da[61];//填充车辆类型
	(*cardata).oxygen_sensors = hex2CombineOne( &da[46] ); //氧气传感器数据

	// 车辆新状态 0504 0x25 附加包信息
	vehicle_new_info_0504_25_info.refuel_st = da[64];// 加油状态
	vehicle_new_info_0504_25_info.refuel_L =  hex2CombineOne(&da[65]);	//加油量

	vehicle_new_info_0504_25_info.once_avg_oil = hex2CombineOne(&da[67]);// 本次启动的平均油耗	
	vehicle_new_info_0504_25_info.total_avg_oil = hex2CombineOne(&da[69]);// 总平均油耗	

	vehicle_new_info_0504_25_info.acc_pedal_value = da[45];//油门踏板开度
	vehicle_new_info_0504_25_info.brake_pedal_value = da[71];//刹车踏板开度
	
	vehicle_new_info_0504_25_info.air_bag_st = da[72];//安全气囊状态

	vehicle_new_info_0504_25_info.safetybelt_st = ((da[9]&0x3e)>>1);//安全带状态

	vehicle_new_info_0504_25_info.steering_wheel_deg = hex2CombineOne(&da[46]);// 方向盘转角	

	// 0504 0x25 end


	if( vin_data_verification( (char *)vehicle_data.vin) == pdPASS )
	{
		if( (memcmp(vehicle_data_old.vin,vehicle_data.vin,17) != 0) )
		{  
			if( vehicle_authentication_mangatio_st_get() != VEHICLE_AUTH_REQ )
			{
				vehicle_authentication_mangatio_st_set( VEHICLE_AUTH_REQ );
			} 
			national808_net_ctrl_infor_set( TER_RUNING_AUTH );
			memcpy(vehicle_data_old.vin,vehicle_data.vin,17);
			
			save_flag = 1;//VIN变了 存储一次
		} 
	}	 

	memcpy(current_data.vin, vehicle_data.vin, 17);
	current_data.brake_gear = vehicle_data.brake_gear;
	current_data.Odo = vehicle_data.Odo;
	current_data.Oil = vehicle_data.Oil;
	current_data.Electricity = vehicle_data.Electricity;
	current_data.Endurance_mileage = vehicle_data.Endurance_mileage;
	event_input_save_data_set((void *)&current_data, sizeof(vehicle_save_data_t));
	if(save_flag == 1)
	{
		if(memcmp((void *)&current_data, (void *)&vehicle_save_data, sizeof(vehicle_save_data_t)) != 0)
		{
			memcpy((void *)&vehicle_save_data, (void *)&current_data, sizeof(vehicle_save_data_t));
			if(gaoz_save_vin_data_infor_write((uint8_t*)&vehicle_save_data,sizeof(vehicle_save_data_t))== pdPASS) 
			{
				gaoz_log_debug_printf(INFOR_MODE,"mcar", "save mcu data ok\r\n");
			}
		}
	}

    return 0;
}




/** ****************************************************************************
* @remarks       static uint8_t sz_ext_status_get(uint8_t *da)
* @brief         神州扩展状态获取
* @param[in]     *da 获取状态的存储地址
* @param[out]    
* @return        获取状态的字节长度
* @attention     无
*******************************************************************************/
uint8_t sz_ext_status_get(uint8_t *da)
{
	// gaoz_log_debug_printf(INFOR_MODE,"800b","sz_ext_status_get  [%d] [%d] [%d][%d] [%d]\n", sz_ext_status_struct.status_len,sz_ext_status_struct.opener_status,sz_ext_status_struct.key_num,sz_ext_status_struct.Reserved[0],sz_ext_status_struct.Reserved[1]);

	if(sz_ext_status_struct.status_len == 0)//未收取到状态信息 传默认
	{
		sz_ext_status_struct.status_len = 18;
		sz_ext_status_struct.opener_status = 0xFF;
		sz_ext_status_struct.key_num = 0xFF;
		sz_ext_status_struct.SST_st = 0xFF;

		// gaoz_log_debug_printf(INFOR_MODE,"800b","sz_ext_status_get set defult value:  [%d] [%d] [%d][%d] [%d]\n",da[0],da[1],da[2],da[3],da[4]);

	}

	memcpy(da,&sz_ext_status_struct,sz_ext_status_struct.status_len+1);

	// gaoz_log_debug_printf(INFOR_MODE,"800b","sz_ext_status_get da  [%d] [%d] [%d][%d] [%d]\n",da[0],da[1],da[2],da[3],da[4]);

	return sz_ext_status_struct.status_len+1;
}



/** ****************************************************************************
* @remarks       static uint8_t sz_ext_status_parse(uint8_t *da)
* @brief         神州扩展状态解析
* @param[in]     *da mcu传回的信息
* @param[out]    
* @return        0成功 
* @attention     无
*******************************************************************************/
static uint8_t sz_ext_status_parse(uint8_t *da)
{  
	gaoz_log_debug_printf(INFOR_MODE,"800b","sz_ext_status_parse [%d] [%d] [%d][%d] [%d] \n", da[2],da[3],da[4],da[5],da[6]);
	memcpy(&sz_ext_status_struct,&da[2],da[2]+1); 
	vehicle_data.auto_start_st = da[5];
	gaoz_log_debug_printf(INFOR_MODE,"800b","mcu d vehicle_data.auto_start_st:%d\n", vehicle_data.auto_start_st);
	return 0;
}

/** ****************************************************************************
* @remarks       uint8_t vehicle_new_info_0504_25_info_get(uint8_t *da)
* @brief         车辆新状态0504附加包25信息获取
* @param[in]     *da 获取状态的存储地址
* @param[out]    
* @return        获取状态的字节长度
* @attention     无
*******************************************************************************/
uint8_t vehicle_new_info_0504_25_info_get(uint8_t *da)
{
	uint8_t index = 0;

	da[index++] = 13;//长度字节 
	
	da[index++] = vehicle_new_info_0504_25_info.refuel_st;// 加油状态

	u16toHex2(vehicle_new_info_0504_25_info.refuel_L,&da[index]);// 加油量
	index += 2;

	u16toHex2(vehicle_new_info_0504_25_info.once_avg_oil,&da[index]);// 自上次启动的平均油耗
	index += 2;

	u16toHex2(vehicle_new_info_0504_25_info.total_avg_oil,&da[index]);// 总平均油耗
	index += 2;

	da[index++] = vehicle_new_info_0504_25_info.acc_pedal_value;// 油门踏板开度

	da[index++] = vehicle_new_info_0504_25_info.brake_pedal_value;// 刹车踏板开度

	da[index++] = vehicle_new_info_0504_25_info.air_bag_st;// 安全气囊状态

	da[index++] = vehicle_new_info_0504_25_info.safetybelt_st;// 安全带状态

	u16toHex2(vehicle_new_info_0504_25_info.steering_wheel_deg,&da[index]);// 方向盘转角
	index += 2;

	 
  
	return index; 
}

/** ****************************************************************************
* @remarks       void vehicle_dtc_code_save(uint8_t *da,uint16_t len)
* @brief         全车故障码的数据存储，格式由MCU定义
* @param[in]     *da mcu传回的信息 len:有效数据的长度
* @param[out]    
* @return        0成功 
* @attention     无
*******************************************************************************/
void vehicle_dtc_code_save(uint8_t *da,uint16_t len)
{
	new_vehicle_fault_code_infor.type = 0;
	new_vehicle_fault_code_infor.model = 0;
	new_vehicle_fault_code_infor.len = len;
	memcpy(new_vehicle_fault_code_infor.vehicle_dtc_info,da,len);

}

/** ****************************************************************************
* @remarks       uint32_t vehicle_dtc_code_get(uint8_t *infor)
* @brief         获取全车故障码的数据，格式由MCU定义
* @param[in]     infor:存储故障码的位置
* @param[out]    获取故障码信息的长度
* @return        0成功 
* @attention     无
*******************************************************************************/
uint32_t vehicle_dtc_code_get( uint8_t *infor )
{
	memcpy(infor,new_vehicle_fault_code_infor.vehicle_dtc_info,new_vehicle_fault_code_infor.len);
	return new_vehicle_fault_code_infor.len;
}

/** ****************************************************************************
* @remarks       static uint8_t warmcarbms_parse(uint8_t *pa,uint16_t len, vehicle_warmcar_package_data_t *cardata)
* @brief         WARMCAR BMS车辆信息
* @param[in]     *pa缓存区，len长度
* @param[out]    cardata 车身数据
* @return        0-成功 1-失败 2-错误
* @attention     无
*******************************************************************************/
static uint8_t warmcarbms_parse(uint8_t *pa,uint16_t len, vehicle_warmcar_package_data_t *cardata)
{
	#define WARMCAR_BMS_MSG_LEN	( 35 )
	uint8_t da[WARMCAR_BMS_MSG_LEN] = { 0 };
	uint8_t pos = 0;

	if( len > WARMCAR_BMS_MSG_LEN )
	{
		return 2;
	}
	memcpy( (uint8_t *)da, (uint8_t *)pa, len );
	/*报警状态*/
	cardata->reserved[0] = da[pos];
	pos += 1;
	/*故障码*/
	//cardata->fault_code = hex4CombineOne( &da[pos] );
	memcpy( (uint8_t *)cardata->fault_code, (uint8_t *)&da[pos], 10 );
	pos += 10;
	/*电池最高电压*/
	cardata->hvbs_number = da[pos];
	pos += 1;
	cardata->hvbc_number = da[pos];
	pos += 1;
	cardata->hv_value = hex2CombineOne( &da[pos] );
	pos += 2;
	/*电池最低电压*/
	cardata->lvbs_number = da[pos];
	pos += 1;
	cardata->lvbc_number = da[pos];
	pos += 1;
	cardata->lv_value =  hex2CombineOne( &da[pos] );
	pos += 2;
	/*电池最高温度*/
	cardata->hts_number = da[pos];
	pos += 1;
	cardata->htp_number = da[pos];
	pos += 1;
	cardata->ht_value = (uint8_t)( hex2CombineOne( &da[pos] ) & 0x00FF );
	pos += 2;
	/*电池最低温度*/
	cardata->lts_number = da[pos];
	pos += 1;
	cardata->ltp_number = da[pos];
	pos += 1;
	cardata->lt_value = (uint8_t)( hex2CombineOne( &da[pos] ) & 0x00FF );
	pos += 2;
	/*动力电池电压*/
	cardata->total_voltage = (uint16_t)hex2CombineOne( (uint8_t *)&da[pos] );
	pos += 2;
	/*动力电池电流*/
	cardata->total_current = (uint16_t)hex2CombineOne( &da[pos] );
	pos += 2;
	/*电池SOH*/
	cardata->bat_soh = (uint16_t)hex2CombineOne( (uint8_t *)&da[pos] );
	pos += 2;
	/*电机控制器温度*/
	cardata->mtr_ctrl_temp = da[pos];
	pos += 1;
	/*电机温度*/
	cardata->mtr_temp = da[pos];
	pos += 1;

    return 0;
}	

/** ****************************************************************************
* @remarks       uint8_t warmcarbms_msg_read( uint8_t *pa,uint16_t len )
* @brief         WARMCAR BMS车辆信息读取
* @param[in]     *pa 目标地址
* @param[out]    无
* @return        数据长度
* @attention     无
*******************************************************************************/
uint8_t warmcarbms_msg_read( uint8_t *pa )
{
	uint8_t pos = 0; 

	if( pa == NULL )
	{
		return 0;
	}
	pa[pos] = vehicle_warmcar_package.hvbs_number;	/*最高电压电池子系统号*/
	pos += 1;
	pa[pos] = vehicle_warmcar_package.hvbc_number;	/*最高电压电池单体代号*/
	pos += 1;
	u16toHex2( vehicle_warmcar_package.hv_value, &pa[pos] );	/*最高电压值，精度 0.001V*/
	pos += 2;
	
	pa[pos] = vehicle_warmcar_package.lvbs_number;	/*最低电压电池子系统号*/
	pos += 1;
	pa[pos] = vehicle_warmcar_package.lvbc_number;	/*最低电压电池单体代号*/
	pos += 1;
	u16toHex2( vehicle_warmcar_package.lv_value, &pa[pos] );	/*最低电压值，精度 0.001V*/
	pos += 2;

	pa[pos] = vehicle_warmcar_package.dev_differ;	/*放电末端压差*/
	pos += 1;
	pa[pos] = vehicle_warmcar_package.cev_differ;	/*充电末端压差*/
	pos += 1;
	
	u16toHex2( vehicle_warmcar_package.total_voltage, &pa[pos] );	/*总电压，精度0.1V*/
	pos += 2;

	u32toHex4( vehicle_warmcar_package.total_current, &pa[pos] );	/*总电流精度 0.1A  偏移-500，即上报值-500后为实际值*/
	pos += 4;

	pa[pos] = vehicle_warmcar_package.hts_number;	/*最高温度子系统号*/
	pos += 1;
	pa[pos] = vehicle_warmcar_package.htp_number;	/*最高温度探针序号*/
	pos += 1;
	pa[pos] = vehicle_warmcar_package.ht_value;		/*最高温度值，精度 1°   偏移-40，即上报值-40后为实际值*/
	pos += 1;
	
	pa[pos] = vehicle_warmcar_package.lts_number;	/*最低温度子系统号*/
	pos += 1;
	pa[pos] = vehicle_warmcar_package.ltp_number;	/*最低温度探针序号*/
	pos += 1;
	pa[pos] = vehicle_warmcar_package.lt_value;		/*最低温度值，精度 1°   偏移-40即上报值-40后为实际值*/
	pos += 1;
	
	//u32toHex4( vehicle_warmcar_package.fault_code, &pa[pos] );/*故障码*/
	memcpy( (uint8_t *)&pa[pos], (uint8_t *)vehicle_warmcar_package.fault_code, 10 );
	pos += 10;

	u32toHex4( vehicle_warmcar_package.charg_state, &pa[pos] );/*BMSInfo：
								Bit0 电流超过150A 触发上报(协议上有放电电流过大报警和充电电流过大报警)
								Bit1 快充插枪状态
								Bit2 慢充插枪状态
								Bit3 快充启动状态
								Bit4 慢充启动状态
								Bit5 快充正常结束
								Bit6 快充异常结束
								Bit7 慢充正常结束
								Bit8 慢充异常结束*/
	pos += 4;

	/*电池SOH*/
	u16toHex2( vehicle_warmcar_package.bat_soh, &pa[pos] );	
	pos += 2;
	/*电机控制器温度*/
	pa[pos] = vehicle_warmcar_package.mtr_ctrl_temp;
	pos += 1;
	/*电机温度*/
	pa[pos] = vehicle_warmcar_package.mtr_temp;
	pos += 1;
	
	/*报警状态*/
	pa[pos] = vehicle_warmcar_package.reserved[0];
	pos += 1;
	/*LED屏幕运行的状态*/
	vehicle_warmcar_package.reserved[1] = warmcarled_heart_state_get(); 
	pa[pos] = vehicle_warmcar_package.reserved[1];
	pos += 1;

	return ( pos );
}

/** ****************************************************************************
* @remarks       static uint8_t warmcarbms_parse(uint8_t *pa,uint16_t len, vehicle_warmcar_package_data_t *cardata)
* @brief         WARMCAR LED屏幕返回的信息
* @param[in]     *pa缓存区，len长度
* @param[out]    cardata 车身数据
* @return        0-成功 1-失败 2-错误
* @attention     无
*******************************************************************************/
static uint8_t warmcarled_parse(uint8_t *pa,uint16_t len, vehicle_warmcar_led_data_t *cardata)
{
	if( len != VEH_WAEMCAR_LED_RET_LEN )
	{
		return 2;
	}
	cardata->ret_size = len;
	memcpy( (uint8_t *)cardata->data, (uint8_t *)pa, len );

	return 0;
}

/** ****************************************************************************
* @remarks       uint8_t warmcarled_data_read( uint8_t *pa )
* @brief         WARMCAR LED屏幕返回数据读取 
* @param[in]     无
* @param[out]    *pa 目标地址
* @return        数据长度
* @attention     无
*******************************************************************************/
uint8_t warmcarled_data_read( uint8_t *pa )
{
	if(( vehicle_warmcar_led_data.ret_size != 0 ) && ( vehicle_warmcar_led_data.ret_size <= VEH_WAEMCAR_LED_RET_LEN ))
	{
		memcpy( (uint8_t *)pa, (uint8_t *)vehicle_warmcar_led_data.data, vehicle_warmcar_led_data.ret_size );
	}
	
	return vehicle_warmcar_led_data.ret_size;
}

/** ****************************************************************************
* @remarks       static void warmcarled_heart_state_set(uint8_t st )
* @brief         WARMCAR LED 心跳状态设置
* @param[in]     st 状态
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void warmcarled_heart_state_set(uint8_t st )
{
	vehicle_warmcar_led_data.run_st = st;
}

/** ****************************************************************************
* @remarks       uint8_t warmcarled_heart_state_get( void )
* @brief         WARMCAR LED 心跳状态 获取
* @param[in]     无
* @param[out]    无
* @return        心跳 状态
* @attention     无
*******************************************************************************/
uint8_t warmcarled_heart_state_get( void )
{
	return vehicle_warmcar_led_data.run_st;
}

/** ****************************************************************************
* @remarks       uint8_t warmcarled_net_data_write( uint8_t *pa, uint32_t len )
* @brief         WARMCAR LED 网络数据 设置
* @param[in]     *pa 数据源地址，len 数据包长度
* @param[out]    *pa 目标地址
* @return        pdFAIL - 失败，pdPASS - 成功
* @attention     无
*******************************************************************************/
uint8_t warmcarled_net_data_write( uint8_t *pa, uint16_t len )
{
	if(( pa == NULL ) || ( len >= VEH_WARMCAR_NET_DATA_LEN ) || ( len == 0 ))
	{
		return pdFAIL;
	}
	if(( len % 8 ) != 0 )
	{
		return pdFAIL;
	}
	if(( vehicle_warmcar_net_data.len != 0x00 ) || ( vehicle_warmcar_net_data.state == 0x01 ))
	{
		return pdFAIL;
	}
	
	vehicle_warmcar_net_data.state = 0x01;
	vehicle_warmcar_net_data.len = len;
	memcpy( (uint8_t *)vehicle_warmcar_net_data.data, (uint8_t *)pa, len );

	return pdPASS;
}

/** ****************************************************************************
* @remarks       uint8_t warmcarled_net_data_read( uint8_t *pa )
* @brief         WARMCAR LED 网络透传数据读取
* @param[in]     无
* @param[out]    *pa 目标地址
* @return        数据长度
* @attention     无
*******************************************************************************/
static uint16_t warmcarled_net_data_read( uint8_t *pa )
{
	uint16_t ret = 0;

	if( pa == NULL )
	{
		return 0;
	}
	if(( vehicle_warmcar_net_data.len != 0 ) && ( vehicle_warmcar_net_data.len <= VEH_WARMCAR_NET_DATA_LEN ))
	{
		pa[0] = 0x01;
		pa[1] = ( uint8_t )(vehicle_warmcar_net_data.len & 0x00FF);
		memcpy( (uint8_t *)&pa[2], (uint8_t *)vehicle_warmcar_net_data.data, vehicle_warmcar_net_data.len );
		ret = vehicle_warmcar_net_data.len + 2;
	}
	
	return ret;
}

/** ****************************************************************************
* @remarks       static uint16_t warmcarled_net_data_clear( void )
* @brief         WARMCAR LED 数据状态清空
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void warmcarled_net_data_clear( void )
{
	memset( (uint8_t *)&vehicle_warmcar_net_data, 0x00, sizeof( vehicle_warmcar_net_data_t ) );
}

/** ****************************************************************************
* @remarks       static uint8_t parse_vehicledata(uint8_t *da, uint16_t len)
* @brief         車輛狀態提取
* @param[in]     *da缓存区，len长度
* @param[out]    无
* @return        0成功 1失败 2结构错误
* @attention     无
*******************************************************************************/
static uint8_t parse_vehicledata(uint8_t *da, uint16_t len)
{
    int ret = 0;

	if(len <= 2)
    {
        gaoz_log_debug_printf(INFOR_MODE,"mcar","len error");
        ret = 2;	
        return ret;
	}
    //gaoz_log_debug_printf(INFOR_MODE,"mcar","parse_vehicledata -%x,%d\r\n",da[0],len);
	switch(da[0])
	{
		case 0x02:
		{

		}
		break;
		case 0x21://神州扩展状态字
				sz_ext_status_parse(da);
				gaoz_log_debug_printf(INFOR_MODE,"mcar","rev 2017 - 0x21 sz_ext_status_parse\r\n",0);
			break;
		case 0x22://全车故障码
				vehicle_dtc_code_save(&da[3],len-3);
				national808_net_ctrl_infor_set( TER_RUNING_VEHICLE_DTC_CODE_REPORT );
				gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu debug rev 2017 - 0x22 read vehicle dtc code len:[%d]\r\n",len-3);
			break;
		case 0xA1:
		{
			if((len == 20))
			{
				if( vin_data_verification( (char *)&da[3] ) == pdPASS )
				{
					memcpy(vehicle_data.vin,&da[3],len-3);
					#if 1
					uint8_t debug_buf[1024] = {0};
					uint16_t debug_buf_len = 0;
					memset(debug_buf,0,sizeof(debug_buf));
					debug_buf_len = HexToAsciiString((char *)debug_buf,(char *)vehicle_data.vin, 17);
					debug_buf[debug_buf_len] = '\r';
					debug_buf_len++;
					debug_buf[debug_buf_len] = '\n';
					debug_buf_len++;
					gaoz_log_debug_printf(INFOR_MODE,"mcar", "vehicle_data.vin:%s,%d\r\n",debug_buf, debug_buf_len );

					memset(debug_buf,0,sizeof(debug_buf));
					debug_buf_len = HexToAsciiString((char *)debug_buf,(char *)vehicle_data_old.vin, 17);
					debug_buf[debug_buf_len] = '\r';
					debug_buf_len++;
					debug_buf[debug_buf_len] = '\n';
					debug_buf_len++;
					gaoz_log_debug_printf(INFOR_MODE,"mcar", "vehicle_data_old.vin:%s,%d\r\n",debug_buf, debug_buf_len );
					#endif
				}

			}
		}
		break;
		case 0x01: //A2 A3
		{
			gaoz_log_debug_printf(INFOR_MODE,"mcar", "rev 2017-01 data save mcu data\r\n",0);
			ret = rcvsplit_parse( &da[3],len-3,&vehicle_data );
		}
		break;
		case 0xA2:
			gaoz_log_debug_printf(INFOR_MODE,"mcar", "warmcarbms_parse: da[3] = %d,%d,%d,%d, len = %d\r\n",da[0],da[1],da[2],da[3], len-3 );
			ret = warmcarbms_parse( &da[3], len-3, &vehicle_warmcar_package );
		break;
		case 0xA3:
		{
			ret = warmcarled_parse( &da[3], len-3, &vehicle_warmcar_led_data );
			if( ret == 0 )
			{
				national808_net_ctrl_infor_set( TER_RUNING_DATA_TRANSFER );
				// if(national808_net_runing_state_get() == TER_RUNING_DATA)
				// {
				// 	national808_net_runing_state_set( TER_RUNING_DATA_TRANSFER );
				// }
			}
		}
		break;	
		case 0xA4:
		{
			
		}
		break;
		case 0xA5:
		{

		}
		break;
		case 0xA7:
		{

		}
		break;
		case 0xAF: /*车辆故障码*/
		{
			if( vehicle_fault_code_infor_set( 0, 0 ,len-3, (uint8_t *)&da[3] ) == pdPASS )
			{
				national808_net_ctrl_infor_set( TER_RUNING_FAULT_CODE_INFOR_SEND );
				// if(national808_net_runing_state_get() == TER_RUNING_DATA)
				// {
				// 	national808_net_runing_state_set( TER_RUNING_FAULT_CODE_INFOR_SEND );
				// 	vehicle_fault_code_state = FAULE_CODE_INIT;
				// }
			}
		}
		break;
		case 0xAB:
		{
	
		}
		break;							
		case 0xB0:
		{

		}
		break;
		
		case 0xEF:
		{
			gaoz_log_debug_printf(INFOR_MODE,"mcar", "rev 2017-EF data save mcu data\r\n",0);
		//	vehicle_save_mcu_data_infor_send();  // 2024年10月31日17:03:37 存储方式换了 全在APP上处理，不再给MCU数据
		}
		break;	
		
		case 0xB1:
		{
			if( vehicle_maintenance_cfg_set( (uint8_t *)&da[3],len-3 ) == pdPASS )
			{	
				national808_net_ctrl_infor_set( TER_RUNING_MAINTENANCE_INFOR_SEND );
				// if(national808_net_runing_state_get() == TER_RUNING_DATA)
				// {
				// 	national808_net_runing_state_set( TER_RUNING_MAINTENANCE_INFOR_SEND );
				// 	vehicle_maintenance_cfg_state_clean();
				// }
			}
		}
		break;
		case 0xB2:
		{
			vehicle_bms_infor_set( (uint8_t *)&da[3],len-3 );
		}
		break;
		default:
		break;
	}

    return ret;
}
/** ****************************************************************************
* @remarks      static uint32_t pkekey_id_match(mcu_send_pkekey_t *data)
* @brief         密钥和滚动码匹配
* @param[in]     
* @param[out]    无
* @return         pdPASS 成功 pdFAIL 失败 
* @attention     无
*******************************************************************************/
static uint32_t pkekey_id_match(mcu_send_pkekey_t *data)
{
	uint32_t ret = pdFAIL;
	uint32_t key_encode = 0;
	uint32_t key_rollcode = 0;

	for(int i=0; i<4; i++)
	{
		key_encode = hex4CombineOne(pke_key.key_app[i].key_encode);
		key_rollcode = hex4CombineOne(pke_key.key_app[i].key_rollcode);
		if((key_encode == (data->key_id)) && (key_encode != 0) && 
			(key_rollcode < (data->key_sn)) && (key_rollcode != 0))
		{
			ret = pdPASS;
			break;
		}
	}
	
	return ret;
}
/** ****************************************************************************
* @remarks      static uint32_t pkekey_code_match(mcu_send_pkekey_t *data)
* @brief         
* @param[in]     
* @param[out]    无
* @return        pdPASS 成功 pdFAIL 失败 
* @attention     无
*******************************************************************************/
static uint32_t pkekey_code_match(mcu_send_pkekey_t *data)
{
	uint32_t ret = pdFAIL;

	if(((data->key_code) == RKE_SHORT_KEY_LOCK)||((data->key_code) == RKE_SHORT_KEY_UNLOCK)||
		((data->key_code) == RKE_SHORT_KEY_PANIC)||((data->key_code) == RKE_LONG_KEY_LOCK)||
		((data->key_code) == RKE_LONG_KEY_UNLOCK))
		{
			ret = pdPASS;
		}
	
	return ret;
}
/** ****************************************************************************
* @remarks      static uint32_t pkekey_app_match(uint32_t data)
* @brief         
* @param[in]     
* @param[out]    无
* @return        pdPASS 成功 pdFAIL 失败 
* @attention     无
*******************************************************************************/
static uint32_t pkekey_app_match(mcu_send_pkekey_t *data)
{
	uint32_t ret = pdFAIL;
	national808_ctrllock_msg_t  ctlock_msg = {0};
	mcu_send_pkekey_t pke_msg = {0};

	if((data->key_code) == RKE_SHORT_KEY_PANIC)
	{
		if( (national808_ctrllock_state_get() == CTLOCK_INIT) ||
			(national808_ctrllock_state_get() == CTLOCK_OK))
		{
			national808_ctrllock_state_set(CTLOCK_PKE_SPK);
			pke_msg.key_id = REV_U32(data->key_id);
			pke_msg.key_sn = REV_U32(data->key_sn);
			pke_msg.key_code = REV_U32(data->key_code);
			memcpy(&mcu_pkekey,&pke_msg,sizeof(mcu_send_pkekey_t));
			national808_net_runing_state_set(TER_RUNING_UPLOAD_PKEKEY);
			if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
			{	
				ctlock_msg.lock_type = 0x03;
				ctlock_msg.lock_res.respondcmd = 0;
				ctlock_msg.lock_res.respondsn = 0;
				ctlock_msg.lock_res.respondsta = 0; 
				ctlock_msg.lock_err = 0;
				ret = national808_ctlock_queue_put(&ctlock_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"mcar","ctlock_queue_put PKE fail!\r\n");
					national808_ctrllock_state_set(CTLOCK_OK);
				}
				else
				{
					if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
					{
						vehiclect_runing_state_set(CARCTL_RUNING_SPEAK_LIGHT);/*鸣笛闪灯状态*/
						national808_ctrllock_state_set( CTLOCK_OK);
					}
					else
					{
						national808_ctrllock_state_set(CTLOCK_OK);
					}
				}
			}
			else
			{
				national808_ctrllock_state_set(CTLOCK_OK);
			}
			ret = pdPASS;
		}
	}
	else if(((data->key_code) == RKE_SHORT_KEY_UNLOCK) || \
			((data->key_code) == RKE_LONG_KEY_UNLOCK))
	{
		if( (national808_ctrllock_state_get() == CTLOCK_INIT) ||
			(national808_ctrllock_state_get() == CTLOCK_OK))
		{
			national808_ctrllock_state_set(CTLOCK_PKE_UNLOCK);
			pke_msg.key_id = REV_U32(data->key_id);
			pke_msg.key_sn = REV_U32(data->key_sn);
			pke_msg.key_code = REV_U32(data->key_code);
			memcpy(&mcu_pkekey,&pke_msg,sizeof(mcu_send_pkekey_t));
			national808_net_runing_state_set(TER_RUNING_UPLOAD_PKEKEY);
			if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
			{
				ctlock_msg.lock_type = 0x01;
				ctlock_msg.lock_res.respondcmd = 0x9563;
				ctlock_msg.lock_res.respondsn = 0;
				ctlock_msg.lock_res.respondsta = 0; 
				ctlock_msg.lock_err = 0;
				ret = national808_ctlock_queue_put(&ctlock_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"mcar","ctlock_queue_put PKE fail!\r\n");
					national808_ctrllock_state_set(CTLOCK_OK);
				}
				else
				{
					if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
					{
						vehiclect_runing_state_set(CARCTL_RUNING_LOCK_UNLOCK);/*控锁状态*/
					}
					else
					{
						national808_ctrllock_state_set(CTLOCK_OK);
					}
				}
			}
			else
			{
				national808_ctrllock_state_set(CTLOCK_OK);
			}
			ret = pdPASS;
		}
	}
	else if(((data->key_code) == RKE_SHORT_KEY_LOCK) || \
			((data->key_code) == RKE_LONG_KEY_LOCK))
	{
		if( (national808_ctrllock_state_get() == CTLOCK_INIT) ||
			(national808_ctrllock_state_get() == CTLOCK_OK))
		{
			national808_ctrllock_state_set(CTLOCK_PKE_LOCK);
			pke_msg.key_id = REV_U32(data->key_id);
			pke_msg.key_sn = REV_U32(data->key_sn);
			pke_msg.key_code = REV_U32(data->key_code);
			memcpy(&mcu_pkekey,&pke_msg,sizeof(mcu_send_pkekey_t));
			national808_net_runing_state_set(TER_RUNING_UPLOAD_PKEKEY);
			if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
			{
				ctlock_msg.lock_type = 0x02;
				ctlock_msg.lock_res.respondcmd = 0x9563;
				ctlock_msg.lock_res.respondsn = 0;
				ctlock_msg.lock_res.respondsta = 0; 
				ctlock_msg.lock_err = 0;
				ret = national808_ctlock_queue_put(&ctlock_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"mcar","ctlock_queue_put PKE fail!\r\n");
					national808_ctrllock_state_set(CTLOCK_OK);
				}
				else
				{
					if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
					{
						vehiclect_runing_state_set(CARCTL_RUNING_LOCK_UNLOCK);/*控锁状态*/
					}
					else
					{
						national808_ctrllock_state_set(CTLOCK_OK);
					}
				}	
			}
			else
			{
				national808_ctrllock_state_set(CTLOCK_OK);
			}
			ret = pdPASS;
		}
	}

	return ret;
}
/** ****************************************************************************
* @remarks       static void parsemcu_protocol(uint8_t * temp, uint16_t len)
* @brief         MCU 协议解析 
* @param[in]     temp缓存区 len长度
* @param[out]    无
* @return        无
* @attention     
*******************************************************************************/
static void parsemcu_protocol(uint8_t * temp, uint16_t len)
{
 	uint8_t reDa = 0;
	mcu_res_msg_t res_msg;
	ota_mcu_request_t req_msg;
	update_result_t upgrade_msg;
	INT32 ret = 0;
	//报文解析使用,文件头
	uint16_t Message_ID;
	uint16_t Message_Property;
	uint8_t Terminal_ID[6];
	uint16_t Message_Serial_Number;
	uint8_t *pMsgBody;

	uint16_t getSerialNum;
	uint16_t getID;
	uint8_t getResult;
	mcu_send_pkekey_t mcu_pkekey_msg = {0};

	char *tmpDa = (char *)gaoz_fibo_malloc(1024*2);
    if (tmpDa == NULL)
    {
		return;
    }
	if (len < 1024)
	{
		memcpy(tmpDa, temp, len);
	}
	else
	{
		gaoz_fibo_free(tmpDa);
		return;
	}	
	Message_ID = (temp[0]<<8)+temp[1];					//消息ID
	Message_Property = ((temp[2] << 8) + temp[3]);	//消息体属性
	memcpy(Terminal_ID, &temp[4], 6);
	Message_Serial_Number = (temp[10] << 8) + temp[11];		//下发流水账号码
	//pMsgBody = &temp[12];								//消息体
	//消息体
	if ((Message_Property & 0x2000) == 0x2000)
	{
		pMsgBody = &temp[16]; 
	}
	else
	{
		pMsgBody = &temp[12];
	}
	Message_Property &= 0x3FF;

	switch (Message_ID)
	{
		case 0x2000://通用應答	
		{
			getSerialNum = char2u16(&pMsgBody[0]);
			getID = char2u16(&pMsgBody[2]);
			getResult = pMsgBody[4];
			if((getID == 0x101C) || (getID == 0x101D) ||
			   (getID == 0x101E) || (getID == 0x101F))
			{
				//nothing
				gaoz_log_debug_printf(INFOR_MODE,"mcar","getSerialNum[%x] getID[%x] getResult[%d]!\r\n",getSerialNum,getID,getResult);   
			}
			else
			{
				if((getID == 0x1015) && (1))
				{
					if(getResult == 0)
					{
						
					}
					else
					{
					
					}
				}
				else if((getID == 0x1031)&&(getResult == 0))
				{
					res_msg.commane = MCU_RESPONSE_LOCK_UNLOCK;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 1031 fail!\r\n");
					}
				}
				else if((getID == 0x1030)&&(getResult == 0))
				{
					res_msg.commane = MCU_RESPONSE_SPEAK_LIGHT;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 1030 fail!\r\n");
					}
				}
				else if((getID == 0x1032)&&(getResult == 0))
				{
					res_msg.commane = MCU_RESPONSE_RELAY;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 1032 fail!\r\n");
					}
				}
				else if((getID == 0x1050)&&(getResult == 0))
				{
					res_msg.commane = MCU_RESPONSE_OTA;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 1050 fail!\r\n");
					}
				}
				else if((getID == 0x1061))
				{
					res_msg.commane = MCU_RESPONSE_SWSIM;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 1061 fail!\r\n");
					}	
				}
				else if((getID == 0x10A1)&&(getResult == 0))
				{
					res_msg.commane = MCU_RESPONSE_STARTPOWER;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 10A1 fail!\r\n");
					}
				}
				else if((getID == 0x10A2)&&(getResult == 0))
				{
					res_msg.commane = MCU_RESPONSE_SETODO;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 10A2 fail!\r\n");
					}
				}
				else if((getID == 0x10A0)&&(getResult == 0))
				{
					res_msg.commane = MCU_RESPONSE_CKYH;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 10A0 fail!\r\n");
					}
				}
				else if((getID == 0x10A5)&&(getResult == 0))
				{
					res_msg.commane = MCU_RESPONSE_WIND;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 10A5 fail!\r\n");
					}
				}
				else if((getID == 0x1081)&&(getResult == 0))
				{
					res_msg.commane = MCU_RESPONSE_FUALT_CODE;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 1081 fail!\r\n");
					}
				}
				else if((getID == 0x1083)&&(getResult == 0))
				{
					res_msg.commane = MCU_RESPONSE_MAINTENANCE_INFOR;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 1083 fail!\r\n");
					}
				}
				else if((getID == 0x1085)&&(getResult == 0))
				{
					res_msg.commane = MCU_RESPONSE_RV_POWER_CTL;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 1085 fail!\r\n");
					}
				}
				else if((getID == 0x10A7))
				{
					print_mcu_flag = 1;
				}
				
				genre_0x1000_Sta((uint8_t *)TERM_ID,Message_ID,Message_Serial_Number,0);
			}
        }
        break;

        case 0x2005://心跳
        {
			warmcarled_heart_state_set( pMsgBody[0] );
            genre_0x1000_Sta((uint8_t *)TERM_ID,Message_ID,Message_Serial_Number,0);
        }
        break;
            
        case 0x2013://版本號
        {
            //提取
			if(Message_Property == 9)
			{			
				#if 1
				uint8_t debug_buf[100] = {0};
				uint16_t debug_buf_len = 0;
				memset(debug_buf,0,sizeof(debug_buf));
				debug_buf_len = HexToAsciiString((char *)debug_buf,(char *)pMsgBody, 9);
				debug_buf[debug_buf_len] = '\r';
				debug_buf_len++;
				debug_buf[debug_buf_len] = '\n';
				debug_buf_len++;
				gaoz_log_debug_printf(INFOR_MODE,"mcar", "MCU verson:%s,%d\r\n",debug_buf, debug_buf_len );
				#endif
				memcpy(mcu_version,pMsgBody,9);
            	genre_0x1000_Sta((uint8_t *)TERM_ID,Message_ID,Message_Serial_Number,0);
				if(vehiclect_runing_state_get() == CARCTL_RUNING_CKVER)
				{
					res_msg.commane = MCU_RESPONSE_CKVER;
					res_msg.results = pdPASS;
					reDa = mcu_send_res_queue_put(&res_msg);
					if(reDa < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 2013 fail!\r\n");
					}
				}
			}
			else
			{
				genre_0x1000_Sta((uint8_t *)TERM_ID,Message_ID,Message_Serial_Number,1);
			}
			
        }
        break; 

        case 0x2011://查詢
        {
            vehicle_portstatus_get( (uint8_t *) 11);
        }
        break; 
        case 0x2016://升級結果通知
        {
            genre_0x1000_Sta((uint8_t *)TERM_ID,Message_ID,Message_Serial_Number,0);
        }
        break;
        case 0x2017://車輛狀態
        {
            reDa = parse_vehicledata(pMsgBody,Message_Property);
			if(vehiclect_runing_state_get() == CARCTL_RUNING_CKCARST)
			{
				res_msg.commane = MCU_RESPONSE_CKCARST;
				res_msg.results = pdPASS;
				reDa = mcu_send_res_queue_put(&res_msg);
				if(reDa < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 2017 fail!\r\n");
				}
				else
				{
					vehiclect_runing_state_set( CARCTL_RUNING_INIT );
				}
			}
            genre_0x1000_Sta((uint8_t *)TERM_ID,Message_ID,Message_Serial_Number,reDa);
        }
        break;  
		case 0x2019://rtc
        {
			genre_0x1000_Sta((uint8_t *)TERM_ID,Message_ID,Message_Serial_Number,0);
        }
        break; 
		case 0x2051://請求app包
		{
			if(vehiclect_runing_state_get() == CARCTL_RUNING_OTA)
			{
				res_msg.commane = MCU_RESPONSE_OTA;
				res_msg.results = pdPASS;
				reDa = mcu_send_res_queue_put(&res_msg);
				if(reDa < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 2051 1050 fail!\r\n");
				}
			}
			if(mcu_ota_st.mcu_ota_st == MCU_OTA_REQUEST )
			{
				req_msg.req_curnum = char2u16(&pMsgBody[0]);
				req_msg.req_total = char2u16(&pMsgBody[2]);
				req_msg.req_length = char2u16(&pMsgBody[4]);
				ret = ota_mcu_request_queue_put(&req_msg);
				if(ret < 1)
				{
					gaoz_log_debug_printf(INFOR_MODE,"mcar","ota_mcu_request_queue_put 2051 fail\r\n");
				}
				vehiclect_runing_state_set(CARCTL_RUNING_UPGRADE);
			}
		}
		break;
		case 0x2052:
		{
			getResult = char2u16(&pMsgBody[0]);
			gaoz_log_debug_printf(INFOR_MODE,"mcar"," 2052 result:%d\r\n",getResult);
			if(getResult != 0)
			{
				if(mcu_ota_st.mcu_ota_overnum > MCU_OTA_OVERNUM)
				{
					if(mcu_ota_st.mcu_ota_st == MCU_OTA_REQUEST )
					{
						mcu_ota_st.mcu_ota_st = MCU_OTA_OVER;
						upgrade_msg.update_result = 1;
						upgrade_msg.update_types = 0;
						if(terota_handle.upgrade_url == URL_MAJOR)
						{
							ret = national808_upgrade_queue_put(&upgrade_msg);
						}
						else
						{
							ret = mangpatio_upgrade_queue_put(&upgrade_msg);
						}
						if(ret < 1)
						{
							gaoz_log_debug_printf(INFOR_MODE,"mcar", "national808_upgrade_queue_put fail\r\n");  
						} 
						wakeup_source_set( POWER_NET );
						mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						vehiclect_runing_state_set(CARCTL_RUNING_INIT);
					}
				}
				else
				{
					mcu_ota_set_overnum();
					mcu_ota_set_status();
					vehicle_ota_sem_set();
					vehiclect_runing_state_set(CARCTL_RUNING_INIT);
				}
			}
			else
			{
				mcu_ota_cle_overnum();
				upgrade_msg.update_result = 0;
                upgrade_msg.update_types = 0;
				if(terota_handle.upgrade_url == URL_MAJOR)
				{
                	ret = national808_upgrade_queue_put(&upgrade_msg);
				}
				else
				{
					ret = mangpatio_upgrade_queue_put(&upgrade_msg);					
				}
                if(ret < 1)
                {
                    gaoz_log_debug_printf(INFOR_MODE,"mcar", "national808_upgrade_queue_put fail\r\n");  
                } 
				wakeup_source_set( POWER_NET );
				mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
				vehiclect_runing_state_set(CARCTL_RUNING_INIT); 	
			}
		}
		break;
		case 0x3001://pc
		{
			parseAuth(pMsgBody,Message_Property,Message_ID,Message_Serial_Number);
		}   
		break; 
		case 0x201D:
		
		break;
		case 0x207D:
		{
			if(Message_Property < sizeof(mcu_send_pkekey_t))
			{

			}
			else
			{
				mcu_pkekey_msg.key_id = hex4CombineOne(pMsgBody);
				mcu_pkekey_msg.key_sn = hex4CombineOne(&pMsgBody[4]);
				mcu_pkekey_msg.key_code = hex4CombineOne(&pMsgBody[8]);
				if(pkekey_id_match(&mcu_pkekey_msg) == pdPASS)
				{
					if(pkekey_code_match(&mcu_pkekey_msg) == pdPASS)
					{
						if(pkekey_app_match(&mcu_pkekey_msg) == pdPASS)
						{
							gaoz_log_debug_printf(INFOR_MODE,"mcar", "valid_pkekey_t:%u,%u,%d\r\n",mcu_pkekey_msg.key_id, mcu_pkekey_msg.key_sn,mcu_pkekey_msg.key_code );
						}
					}
				}
			}
			gaoz_log_debug_printf(INFOR_MODE,"mcar", "mcu_send_pkekey_t:%u,%u,%d\r\n",mcu_pkekey_msg.key_id, mcu_pkekey_msg.key_sn,mcu_pkekey_msg.key_code );
		}
		break;
		case 0x20A6:
		{
			res_msg.commane = MCU_RESPONSE_STARTPOWER;
			res_msg.results = pdPASS;
			reDa = mcu_send_res_queue_put(&res_msg);
			if(reDa < 1)
			{
				gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_put 10A1 fail!\r\n");
			}
			if( vehicle_engine_start_result_set( (uint8_t *)&pMsgBody[0] ) == pdPASS )
			{
				national808_net_ctrl_infor_set( TER_RUNING_START_ENGINE_RESULT );
				// if(national808_net_runing_state_get() == TER_RUNING_DATA)
				// {
				// 	national808_net_runing_state_set( TER_RUNING_START_ENGINE_RESULT );
				// }
			}
		}
		break;
		case 0x2084: 	/*GD 向L610 发送SEED */
			if( vehicle_seed_infor_set( &pMsgBody[0] ) == pdPASS )
			{	
				national808_net_ctrl_infor_set( TER_RUNING_SEED_INFOR_SEND );
			}
		break;
		case 0x2087:	/*GD向L610发送实时数据包*/
			if( vehicle_adas_infor_set( &pMsgBody[0] ) == pdPASS )
			{
				national808_net_ctrl_infor_set( TER_RUNING_ADAS_INFOR_SEND );
				genre_0x1000_Sta((uint8_t *)TERM_ID,Message_ID,Message_Serial_Number,0);
			}
			else
			{
				genre_0x1000_Sta((uint8_t *)TERM_ID,Message_ID,Message_Serial_Number,1);
			}
		break;
		default:
            genre_0x1000_Sta((uint8_t *)TERM_ID,Message_ID,Message_Serial_Number,2);
        break;
    }
	gaoz_fibo_free(tmpDa);
}

/** ****************************************************************************
* @remarks       static void parse_mcu_recv_data( uint8_t *da, uint16_t len )
* @brief         接受数据缓存
* @param[in]     *da缓存区，len长度
* @param[out]    无
* @return        无
* @attention     
*******************************************************************************/
static void parse_mcu_recv_data( uint8_t *da, uint16_t len )
{
    //uint32_t res = pdFAIL;    
	uint16_t CR_i;
	uint16_t tmpLen, RawDaLen;
	uint16_t CR_i_Start;
	uint16_t iStart, iEnd;	//记录当前包的开始和结束位置

	uint16_t i,j;

	uint8_t *GPRS_Response = da;
	uint16_t AllPac_Len;

    gaoz_mutex_lock(mcu_recv_data_mutex);
	gaoz_power_man_wakeup_task_num_run(); 
	AllPac_Len = len;
    uint8_t *temp = (uint8_t *)gaoz_fibo_malloc(1024*1);
    if (temp == NULL)
    {
        return ;
    }

	if (AllPac_Len == 0)
	{
		gaoz_fibo_free(temp);
		return ;
	}

	CR_i = 0;

	while (CR_i < AllPac_Len)
	{
		CR_i_Start = CR_i;

		if (mcu_recv_data.len != 0)	
		{
			//说明上次有半包情况，半包情况，在extr_da中，必然第一个是7E
			memcpy(temp, mcu_recv_data.data, mcu_recv_data.len);

			//开始找尾
			while (GPRS_Response[CR_i] != 0x7E)
			{
				CR_i ++;
				if (CR_i >= AllPac_Len)
				{
					//极端情况，整包数据，没有结尾的7e
					tmpLen = mcu_recv_data.len + CR_i - CR_i_Start;
					//先判断数组不要越界
					if (tmpLen > N808MCU_RX_BUF_SIZE)
					{
						//假设收到了外太空信号，不处理
						gaoz_fibo_free(temp);
						return ;
					}

					memcpy(&mcu_recv_data.data[mcu_recv_data.len], &GPRS_Response[CR_i_Start], CR_i - CR_i_Start);
					mcu_recv_data.len = tmpLen;
					gaoz_fibo_free(temp);
					return ;
				}
			}

			//找到尾巴了，把这段数据存入temp数据，之后等待进行转义的处理
			if ( (mcu_recv_data.len + CR_i - CR_i_Start + 1) < N808MCU_RX_BUF_SIZE )
			{
				memcpy(&temp[mcu_recv_data.len], &GPRS_Response[CR_i_Start], CR_i - CR_i_Start + 1);
				//temp中的数据，包括头尾
				RawDaLen = mcu_recv_data.len + CR_i - CR_i_Start + 1;
			}
			else
			{
				//temp中的数据，包括头尾
				RawDaLen = 0;
			}

			mcu_recv_data.len = 0;
			CR_i ++; //保证下次检查数据，是最新的
		}
		else
		{
			//上一包没有残余数据, 找头
			while (GPRS_Response[CR_i] != 0x7E)
			{
				CR_i ++;
				if (CR_i >= AllPac_Len)
				{
					//极端情况，一包数据，只收到了两个7e中间的 几个字节，暂时不考虑
					gaoz_fibo_free(temp);
					return ;
				}
			}
			iStart = CR_i; //找到了7E头
			//开始找尾
			CR_i ++;
			if (CR_i >= AllPac_Len)
			{
				tmpLen = CR_i - iStart;

				//先判断数组不要越界
				if (tmpLen > N808MCU_RX_BUF_SIZE)
				{
					tmpLen = 0;
				}
				//属于残余数据，保存进extr_da
				memcpy(mcu_recv_data.data, &GPRS_Response[iStart], tmpLen);
				mcu_recv_data.len = tmpLen;
				gaoz_fibo_free(temp);
				return ;
			}

			while (GPRS_Response[CR_i] != 0x7E)
			{
				CR_i ++;
				if (CR_i >= AllPac_Len)
				{
					tmpLen = CR_i - iStart;

					//先判断数组不要越界
					if (tmpLen > N808MCU_RX_BUF_SIZE)
					{
						tmpLen = 0;
					}
					//属于残余数据，保存进extr_da
					memcpy(mcu_recv_data.data, &GPRS_Response[iStart], tmpLen);
					mcu_recv_data.len = tmpLen;
					gaoz_fibo_free(temp);
					return ;
				}
			}
			iEnd = CR_i; //找到了7E end tag

			CR_i ++; //保证下次检查数据，是最新的

			//找到尾巴了，把这段数据存入temp数据，之后等待进行转义的处理
			if ( (iEnd - iStart + 1) < N808MCU_RX_BUF_SIZE )
			{
				memcpy(temp, &GPRS_Response[iStart], iEnd - iStart + 1);
				//temp中的数据，包括头尾
				RawDaLen = iEnd - iStart + 1;
			}
			else
			{
				RawDaLen = 0;
			}			
		}

		if (RawDaLen == 0)
		{
			continue;
		}
		//转义
		//不再解析头尾
		RawDaLen --; 
		if (RawDaLen == 1)
		{
			//说明只收到了两个7E，有可能就是中间漏掉一包，为了防止
			//两个7E，我们再重新查找数据，最多丢一包
			CR_i --;
			continue;
		}
		for (i=1,j=0;i<RawDaLen;i++)
		{
			if ( (temp[i] == 0x7D) && (temp[i+1] == 0x02) )
			{
				temp[j++] = 0x7E;
				i++;
			}
			else if ( (temp[i] == 0x7D) && (temp[i+1] == 0x01) )
			{
				temp[j++] = 0x7D;
				i++;
			}
			else
			{
				temp[j++] = temp[i];
			}
		}

		// 计算校验，只有校验OK才可以解析
		if (get_chk_xor(temp, j) != 0)
		{		
			continue;
		}

		//把解析单独弄出去，清晰些
		parsemcu_protocol(temp, j);
        //res = pdPASS;
	}
	gaoz_fibo_free(temp);
    gaoz_mutex_unlock( mcu_recv_data_mutex );
	gaoz_power_man_wakeup_task_num_stop();
    //return res;
}
/** ****************************************************************************
* @remarks       void getopenlockerrcode(n808_vehicle_data_t *data_vehicle, uint16_t *data)
* @brief         获取开锁指令错误码
* @param[in]     *data_vehicle车身数据
* @param[out]    *data错误码
* @return        无
* @attention     
*******************************************************************************/
void getopenlockerrcode(n808_vehicle_data_t *data_vehicle, uint16_t *data)
{
	u16 datp = 0;

	if(((data_vehicle->speed) != 0) && (((data_vehicle->Ignition_status)&0x08) != 0))
	{
		datp |= 0x009;
	}
/*	if(((data_vehicle->doors_status)&0x0f) != 0)
	{
		datp |= 0x002;
	}
	if(((data_vehicle->doors_status)&0x10) != 0)
	{
		datp |= 0x004;
	}
*/
/*	if(((data_vehicle->Ignition_status)&0x08) != 0)
	{
		datp |= 0x008;
	}*/
/*	if(((data_vehicle->lights_status)&0x03) != 0)
	{
		datp |= 0x010;
	}
	if(((data_vehicle->lights_status)&0x04) != 0)
	{
		datp |= 0x040;
	}
*/	
	if(/*(((data_vehicle->brake_gear)&0x14) == 0x00) && */
	  (((data_vehicle->Ignition_status)&0x08) != 0))
	{
		datp |= 0x008;
	}
	/*if(((data_vehicle.brake_gear)&0x01) != 0x01)
	{
		datp |= 0x100;
	}*/

	*data = datp;
}
/** ****************************************************************************
* @remarks       void getcloselockerrcode(n808_vehicle_data_t *data_vehicle, uint16_t *data)
* @brief         获取锁门指令错误码
* @param[in]     *data_vehicle车身数据
* @param[out]    *data错误码
* @return        无
* @attention     
*******************************************************************************/
void getcloselockerrcode(n808_vehicle_data_t *data_vehicle, uint16_t *data)
{
	u16 datp = 0;

	if((data_vehicle->speed) != 0)/*车速*/
	{
		datp |= 0x001;
	}
	if(((data_vehicle->doors_status)&0x0f) != 0)/*四个车门*/
	{
		datp |= 0x002;
	}
	if(((data_vehicle->doors_status)&0x10) != 0)/*行李箱*/
	{
		datp |= 0x004;
	}
	if(((data_vehicle->Ignition_status)&0x08) != 0)/*ACC*/
	{
		datp |= 0x008;
	}
	 
	if(((data_vehicle->lights_status)&0x03) != 0)/*远光 近光*/
	{
		datp |= 0x010;
	}
	if(((data_vehicle->lights_status)&0x04) != 0)/*示廓 不判定双闪转向灯*/
	{
		datp |= 0x040;
	}
	 
	/*判断当前挡位是否处于P档或者N档，当不处于这两个挡位时BIT7=1*/
	if( (((data_vehicle->brake_gear)&0x04) != 0x04) && (((data_vehicle->brake_gear)&0x10) != 0x10) ) 
	{
		datp |= 0x080;
	}
	if(((data_vehicle->brake_gear)&0x01) != 0x01 )/*手刹*/
	{
		datp |= 0x100;
	}
	
	*data = datp;
}
/** ****************************************************************************
* @remarks       uint32_t vehicle_ctrl_manage_fun( national_send_data_e *send_st , national_response_e *recv_st)
* @brief         控车管理功能
* @param[in]     无
* @param[out]    *send_st 发送状态 *recv_st接收状态
* @return        pdPASS 数据发送失败 pdFAIL 数据发送成功
* @attention     
*******************************************************************************/
static uint32_t vehicle_ctrl_manage_fun( mcu_send_data_e *send_st , mcu_response_e *recv_st)
{
    uint32_t ret = pdFAIL;
	uint8_t locktype = 0;
	//uint32_t getodo = 0;
	uint8_t send_data[200] = {0};
	uint16_t send_len = 0;
    vehicle_ctrl_run_state_e run_st;
	national808_ctrllock_msg_t ctlock_msg = {0};
	static uint8_t maintain_set = 0;
	run_st = vehiclect_runing_state_get();

    *send_st = MCU_SEND_ERR;
    *recv_st = MCU_NO_RESPONSE;
	switch( run_st )
	{
		case CARCTL_RUNING_LOCK_UNLOCK:
			if(( national808_ctlock_queue_get( &ctlock_msg , 200 ) == pdPASS ) ||
			 (mangpatio_ctlock_queue_get ( &ctlock_msg , 200) == pdPASS) )
			{	 
				gaoz_log_debug_printf(INFOR_MODE,"mcar","ctlock_msg : %d\r\n",ctlock_msg.lock_type);
				mcu_send_data_st.send_type = ctlock_msg.lock_type;
				locktype = ctlock_msg.lock_type;
				mcu_send_data_st.respondcmd = ctlock_msg.lock_res.respondcmd;
				mcu_send_data_st.respondsn = ctlock_msg.lock_res.respondsn;
				if((ctlock_msg.lock_type == 1) || (ctlock_msg.lock_type == 7) ||
				   (ctlock_msg.lock_type == 0x82) || (ctlock_msg.lock_type == 0x62) ||
				   (ctlock_msg.lock_type == 0x21) || (ctlock_msg.lock_type == 0x27))
				{
					#if USER_HXJH
					getopenlockerrcode(&vehicle_data,&mcu_send_data_st.lockerr);
					if(mcu_send_data_st.lockerr != 0)
					{
						ctlock_msg.lock_err = mcu_send_data_st.lockerr;
						ctlock_msg.lock_res.respondcmd = mcu_send_data_st.respondcmd;
						ctlock_msg.lock_res.respondsn = mcu_send_data_st.respondsn;
						ctlock_msg.lock_res.respondsta = 1;
						ctlock_msg.lock_type = mcu_send_data_st.send_type;
						if((ctlock_msg.lock_type == 0x82) || (ctlock_msg.lock_type == 0x62))
						{
							ret = bluetooth_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","bt_ctlock_res_queue_put  fail!\r\n");
							}
							ret = pdFAIL;	
						}
						else if((ctlock_msg.lock_type == 0x21) || (ctlock_msg.lock_type == 0x27))
						{
							ret = mangpatio_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","mangpatio_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						}
						else
						{
							ret = national808_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","national808_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;  
							wakeup_source_set( POWER_NET );                                   
						}
						vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
						// if((mcu_send_data_st.send_type < 0x30))
						// {
						// 	wakeup_source_set( POWER_NET );
						// 	mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						// }
						memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
					}
					else
					{
						if((ctlock_msg.lock_type == 0x82) || (ctlock_msg.lock_type == 0x62)||
						(ctlock_msg.lock_type == 0x21) || (ctlock_msg.lock_type == 0x27))
						{
							locktype = 1;
						}
						ret = sendto_mcu_info(0x1031,(uint8_t *)TERM_ID,&locktype,1);
						gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1031 : %d\r\n",ret);
						if(ret == pdPASS)
						{
							*send_st = MCU_SEND_OK;
							*recv_st = MCU_HAVE_RESPONSE;
						}
						else
						{
							log_debug_printf(ERROR_MODE,VEH_CTRL_NAME ,"[%s]sendto_mcu_info unlock fail\r\n",sys_err_infor_pointer_get( 56 ));
						}
					}
					#else

					#if (OS_MCU_RELAY_LOCK_SYNC == 0)// 断电继电器与锁车动作不同步执行
				 		locktype = 1; 
					#else
					if((ctlock_msg.lock_type == 0x62)||(ctlock_msg.lock_type == 0x27)|| (ctlock_msg.lock_type == 0x07))
					{
						locktype = 7;/*开锁+通电*/
					}
					else
					{
						locktype = 1;/*仅开锁*/
					} 
					#endif

					ret = sendto_mcu_info(0x1031,(uint8_t *)TERM_ID,&locktype,1);
					gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1031:locktype:%d  ret: %d\r\n",locktype,ret); 
					if(ret == pdPASS)
					{
						*send_st = MCU_SEND_OK;
						*recv_st = MCU_HAVE_RESPONSE;
					}
					else
					{
						log_debug_printf(ERROR_MODE,VEH_CTRL_NAME ,"[%s]sendto_mcu_info unlock fail\r\n",sys_err_infor_pointer_get( 56 ));
					}
					#endif   /*end USER_HXJH*/
				}
				else if((ctlock_msg.lock_type == 0x13) || (ctlock_msg.lock_type == 0x14)// 主
						||(ctlock_msg.lock_type == 0x33) || (ctlock_msg.lock_type == 0x34))// 辅
				{/*0x13：SST（发动机自动启停系统）功能开启
					0x14：SST（发动机自动启停系统）功能关闭 */
 

					locktype = ctlock_msg.lock_type&0x17;//去掉辅平台标识
					ret = sendto_mcu_info(0x1031,(uint8_t *)TERM_ID,&locktype,1);
					gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu d SST sendto_mcu_info 1031: %d\r\n",ctlock_msg.lock_type);
					if(ret == pdPASS)
					{
						*send_st = MCU_SEND_OK;
						*recv_st = MCU_HAVE_RESPONSE;
					}
					else
					{
						log_debug_printf(ERROR_MODE,VEH_CTRL_NAME ,"[%s]sendto_mcu_info unlock fail\r\n",sys_err_infor_pointer_get( 56 ));
					} 
				}
				else if((ctlock_msg.lock_type == 0x03) || (ctlock_msg.lock_type == 0x23))
				{/* 自动开关锁 */
					if((vehicle_data.lock&0x01) == 1)/*当前开锁*/
					{
						locktype = 02;//锁车 
					}
					else /*当前关锁*/
					{
						locktype = 01;//解锁 ctlock_msg.lock_type
					}
					ctlock_msg.lock_type =(ctlock_msg.lock_type & 0X20);//确定主辅平台
					ctlock_msg.lock_type |= locktype;//确定锁动作
					
					ret = sendto_mcu_info(0x1031,(uint8_t *)TERM_ID,&locktype,1);
					gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1031:auto locktype:%d  ret: %d\r\n",locktype,ret); 
					if(ret == pdPASS)
					{
						*send_st = MCU_SEND_OK;
						*recv_st = MCU_HAVE_RESPONSE;
					}
					else
					{
						log_debug_printf(ERROR_MODE,VEH_CTRL_NAME ,"[%s]sendto_mcu_info unlock fail\r\n",sys_err_infor_pointer_get( 56 ));
					}
				}
				else 
				{ 
				/*神州要求我们将锁车判断条件去掉，下指令直接锁车。*/ 
				#if( OS_FUNCTION_LOCK_CHECK_FUNCTION == 1 )	
					getcloselockerrcode(&vehicle_data,&mcu_send_data_st.lockerr);
					if(mcu_send_data_st.lockerr != 0)
					{
						ctlock_msg.lock_err = mcu_send_data_st.lockerr;
						ctlock_msg.lock_res.respondcmd = mcu_send_data_st.respondcmd;
						ctlock_msg.lock_res.respondsn = mcu_send_data_st.respondsn;
						ctlock_msg.lock_res.respondsta = 1;
						ctlock_msg.lock_type = mcu_send_data_st.send_type;
						if((ctlock_msg.lock_type == 0x83) || (ctlock_msg.lock_type == 0x63))
						{
							ret = bluetooth_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","bt_ctlock_res_queue_put  fail!\r\n");
							}
							ret = pdFAIL;	
						}
						else if((ctlock_msg.lock_type == 0x22) || (ctlock_msg.lock_type == 0x28))
						{
							ret = mangpatio_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","mangpatio_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						}
						else
						{
							ret = national808_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","national808_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							wakeup_source_set( POWER_NET );
						}
						vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
						// if((mcu_send_data_st.send_type < 0x30))
						// {
						// 	wakeup_source_set( POWER_NET );
						// 	mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						// }
						memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
						
						#if (OS_LOCK_FAIL_FIND_FUNCTION == 1)
					 
						/* 下发鸣笛闪灯 */
						ctlock_msg.lock_type = 0x03;
						ctlock_msg.lock_res.respondcmd = 0;
						ctlock_msg.lock_res.respondsn = 0;
						ctlock_msg.lock_res.respondsta = 0; 
						ctlock_msg.lock_err = 0;
						ret = national808_ctlock_queue_put(&ctlock_msg);
						if(ret < 1)
						{
							gaoz_log_debug_printf(INFOR_MODE,"mcar","ctlock_queue_put PKE fail!\r\n");
							national808_ctrllock_state_set(CTLOCK_OK);
						}
						else
						{
							if(vehiclect_runing_state_get() == CARCTL_RUNING_INIT)
							{
								vehiclect_runing_state_set(CARCTL_RUNING_SPEAK_LIGHT);/*鸣笛闪灯状态*/
								national808_ctrllock_state_set( CTLOCK_OK);
							}
							else
							{
								national808_ctrllock_state_set(CTLOCK_OK);
							}
						}
						#endif
					}
					else
					{
						#if (OS_MCU_RELAY_LOCK_SYNC == 0)// 断电继电器与锁车动作不同步执行
							locktype = 2; 
						#else
						if((ctlock_msg.lock_type == 0x63)||(ctlock_msg.lock_type == 0x28)|| (ctlock_msg.lock_type == 0x08))
						{
							locktype = 8;/*锁车+断电*/
						}
						else
						{
							locktype = 2;/*仅锁车*/
						} 
						#endif

						ret = sendto_mcu_info(0x1031,(uint8_t *)TERM_ID,&locktype,1);
						gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1031:locktype:%d  ret: %d\r\n",locktype,ret); 
						if(ret == pdPASS)
						{
							*send_st = MCU_SEND_OK;
							*recv_st = MCU_HAVE_RESPONSE;
						}
						else
						{

						}
					}
				#else
				
					#if (OS_MCU_RELAY_LOCK_SYNC == 0)// 断电继电器与锁车动作不同步执行
						locktype = 2; 
					#else
					if((ctlock_msg.lock_type == 0x63)||(ctlock_msg.lock_type == 0x28)|| (ctlock_msg.lock_type == 0x08))
					{
						locktype = 8;/*锁车+断电*/
					}
					else
					{
						locktype = 2;/*仅锁车*/
					} 
					#endif 
					ret = sendto_mcu_info(0x1031,(uint8_t *)TERM_ID,&locktype,1);
					gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1031:locktype:%d  ret: %d\r\n",locktype,ret); 
					if(ret == pdPASS)
					{
						*send_st = MCU_SEND_OK;
						*recv_st = MCU_HAVE_RESPONSE;
					}
				#endif
				}
			}
			else
			{
				if(mcu_send_data_st.send_type != 0)
				{
					if(mcu_send_data_st.send_cnt ++ < 3)
					{
						if((mcu_send_data_st.send_type  == 0x82) || (mcu_send_data_st.send_type  == 0x62) ||
						  (mcu_send_data_st.send_type  == 1) || (mcu_send_data_st.send_type  == 7) ||
							(mcu_send_data_st.send_type  == 0x21) || (mcu_send_data_st.send_type  == 0x27))
						{
							if((mcu_send_data_st.send_type  == 7) || (mcu_send_data_st.send_type  == 0x27))
							{
								locktype = 7;
							}
							else
							{
								locktype = 1;
							}
						}
						else
						{
							if((mcu_send_data_st.send_type  == 8) || (mcu_send_data_st.send_type  == 0x28))
							{
								locktype = 8;
							}
							else
							{
								locktype = 2;
							}
						}

						ret = sendto_mcu_info(0x1031,(uint8_t *)TERM_ID,&locktype,1);
						if(ret == pdPASS)
						{
							*send_st = MCU_SEND_OK;
							*recv_st = MCU_HAVE_RESPONSE;
						}
					}
					else
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_data_st.send_cnt 3\r\n");
						vehiclect_runing_state_set(CARCTL_RUNING_WAIT);	
					}
				}
			}
			gaoz_power_man_wakeup_task_num_run();  /*wake up*/ 
			national808_ctlock_time_tick = gaoz_get_systick(); 			
		break;
		case CARCTL_RUNING_SPEAK_LIGHT:
			if(( national808_ctlock_queue_get( &ctlock_msg , 200 ) == pdPASS ) ||
			   ( mangpatio_ctlock_queue_get ( &ctlock_msg , 200 ) == pdPASS) )
			{
				gaoz_log_debug_printf(INFOR_MODE,"mcar","ctlock_msg : %d\r\n",ctlock_msg.lock_type);
				locktype = ctlock_msg.lock_type;
				if(ctlock_msg.lock_type == 0x60)
				{
					locktype = 1;
				}
				else if(ctlock_msg.lock_type == 0x68)
				{
					locktype = 2;
				}
				else if(ctlock_msg.lock_type == 0x67)
				{
					locktype = 3;
				}
				else if((locktype&0x20) == 0x20)
				{
					locktype &= ~0x20;
				}
				ret = sendto_mcu_info(0x1030,(uint8_t *)TERM_ID,&locktype,1);
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info : %d\r\n",ret);
				if(ret == pdPASS)
				{
					*send_st = MCU_SEND_OK;
					*recv_st = MCU_HAVE_RESPONSE;
					ctlock_msg.lock_err = 0;
				}
				else
				{
					ctlock_msg.lock_err = 1;
				}
				
				ctlock_msg.lock_res.respondcmd = 0;
				ctlock_msg.lock_res.respondsn = 0;
				ctlock_msg.lock_res.respondsta = 0;
				ctlock_msg.lock_type = ctlock_msg.lock_type;
				if(ctlock_msg.lock_type >= 0x60)
				{
					ret = bluetooth_ctlock_res_queue_put(&ctlock_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","bt_ctlock_res_queue_put CARCTL_RUNING_SPEAK_LIGHT fail!\r\n");
					}
					ret = pdPASS;	
				}
			}
			vehiclect_runing_state_set(CARCTL_RUNING_INIT);			
		break;
		case CARCTL_RUNING_WAIT:
			
			if( pdPASS == sys_timestamp_delay(( uint32_t * )&national808_ctlock_time_tick, CTRL_LOCK_TIME_PERIOD * GAOZ_TICK_PERIOD_S) )
        	{
				// vehicle_info_report_semaphore_put();//主动上报一条0504

				mcu_send_data_st.lockerr = 0x200;
				ctlock_msg.lock_err = mcu_send_data_st.lockerr;
				ctlock_msg.lock_res.respondcmd = mcu_send_data_st.respondcmd;
				ctlock_msg.lock_res.respondsn = mcu_send_data_st.respondsn;
				ctlock_msg.lock_res.respondsta = 1;
				ctlock_msg.lock_type = mcu_send_data_st.send_type;
				if((mcu_send_data_st.send_type < 0x10) 
				|| (mcu_send_data_st.send_type ==  0X13) ||(mcu_send_data_st.send_type == 0X14))//启停
				{
					gaoz_log_debug_printf(INFOR_MODE,"mcar","ctlock_msg.lock_err:%d,ctlock_msg.lock_res.respondsta:%d,ctlock_msg.lock_type:%d\r\n",ctlock_msg.lock_err,ctlock_msg.lock_res.respondsta,ctlock_msg.lock_type);
					ret = national808_ctlock_res_queue_put(&ctlock_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","national808_ctlock_res_queue_put 0563 fail!\r\n");
					}
					ret = pdFAIL;
					wakeup_source_set( POWER_NET );
				}
				else if((mcu_send_data_st.send_type < 0x30)
				|| (mcu_send_data_st.send_type ==  0X33) ||(mcu_send_data_st.send_type == 0X34))
				{
					ret = mangpatio_ctlock_res_queue_put(&ctlock_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mangpatio_ctlock_res_queue_put 0563 fail!\r\n");
					}
					ret = pdFAIL;
					mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
				}
				else
				{
					ret = bluetooth_ctlock_res_queue_put(&ctlock_msg);
					if(ret < 1)
					{
						gaoz_log_debug_printf(INFOR_MODE,"mcar","bt_ctlock_res_queue_put  fail!\r\n");
					}
					ret = pdFAIL;
				}
				// if((mcu_send_data_st.send_type < 0x30))
				// {
				// 	wakeup_source_set( POWER_NET );
				// 	mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
				// }
				vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
				memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
				gaoz_log_debug_printf(INFOR_MODE,"mcar","national808_ctlock_time_tick 5s\r\n");
				gaoz_power_man_wakeup_task_num_stop();
			}
			else
			{
				gaoz_power_man_wakeup_task_num_run();  /*wake up*/
				if((mcu_send_data_st.send_type == 1) || (mcu_send_data_st.send_type == 7) ||
				   (mcu_send_data_st.send_type == 0x82) || (mcu_send_data_st.send_type == 0x62) ||
				   (mcu_send_data_st.send_type == 0x21) || (mcu_send_data_st.send_type == 0x27))
				{
					if((vehicle_data.lock&0x01) == 1)
					{ 
						// vehicle_info_report_semaphore_put();//主动上报一条0504

						mcu_send_data_st.lockerr = 0;
						ctlock_msg.lock_err = mcu_send_data_st.lockerr;
						ctlock_msg.lock_res.respondcmd = mcu_send_data_st.respondcmd;
						ctlock_msg.lock_res.respondsn = mcu_send_data_st.respondsn;
						ctlock_msg.lock_res.respondsta = 0;
						ctlock_msg.lock_type = mcu_send_data_st.send_type;
						if((mcu_send_data_st.send_type == 0x82) || (mcu_send_data_st.send_type == 0x62))
						{
							ret = bluetooth_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","bt_ctlock_res_queue_put  fail!\r\n");
							}
							ret = pdFAIL;	
						}
						else if((mcu_send_data_st.send_type == 0x21) || (mcu_send_data_st.send_type == 0x27))
						{
							ret = mangpatio_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","mangpatio_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						}
						else
						{
							ret = national808_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","national808_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							wakeup_source_set( POWER_NET );
						}
						// if(mcu_send_data_st.send_type < 0x30)
						// {
						// 	wakeup_source_set( POWER_NET );
						// 	mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						// }
						if((mcu_send_data_st.send_type == 0x07) || (mcu_send_data_st.send_type == 0x62) || (mcu_send_data_st.send_type == 0x27))
						{
							vehiclect_runing_state_set(CARCTL_RUNING_RELAY);	
						}
						else
						{
							vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
						}
						//gaoz_power_man_wakeup_task_num_stop();  /*wake up*/
						memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
						gaoz_log_debug_printf(INFOR_MODE,"mcar","national808_ctlock_res_queue_put lock 1\r\n");
					}
				}
				else if((mcu_send_data_st.send_type == 0x13) || (mcu_send_data_st.send_type == 0x14) || 
				(mcu_send_data_st.send_type == 0x33) || (mcu_send_data_st.send_type == 0x34))
				{/*0x13：SST（发动机自动启停系统）功能开启
					0x14：SST（发动机自动启停系统）功能关闭 */
					uint8_t result = 0;

					if((mcu_send_data_st.send_type == 0x13) || (mcu_send_data_st.send_type == 0x34))//开启
					{
						if(vehicle_data.auto_start_st == 1)
						{
							result  = 1;
							gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu d SST start open suc.!\r\n");
						}

					}

					if((mcu_send_data_st.send_type == 0x14) || (mcu_send_data_st.send_type == 0x34))//关闭
					{
						if(vehicle_data.auto_start_st == 0)
						{
							result  = 1;
							gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu d SST start close suc.!\r\n");
						} 
					}


					if(result) 
					{ 
						// vehicle_info_report_semaphore_put();//主动上报一条0504
						gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu d SST start close suc.! send 0563\r\n");
						mcu_send_data_st.lockerr = 0;
						ctlock_msg.lock_err = mcu_send_data_st.lockerr;
						ctlock_msg.lock_res.respondcmd = mcu_send_data_st.respondcmd;
						ctlock_msg.lock_res.respondsn = mcu_send_data_st.respondsn;
						ctlock_msg.lock_res.respondsta = 0;
						ctlock_msg.lock_type = mcu_send_data_st.send_type;
						 
						if((mcu_send_data_st.send_type == 0x33) || (mcu_send_data_st.send_type == 0x34))
						{
							ret = mangpatio_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","mangpatio_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						}
						else
						{
							ret = national808_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","national808_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							wakeup_source_set( POWER_NET );
						}
						 
						// wakeup_source_set( POWER_NET );
						// mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						 
						 
						vehiclect_runing_state_set(CARCTL_RUNING_INIT);	 
						//gaoz_power_man_wakeup_task_num_stop();  /*wake up*/
						memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
						gaoz_log_debug_printf(INFOR_MODE,"mcar","national808_ctlock_res_queue_put lock 1\r\n");
					}

				}
				else
				{
				#if( OS_FUNCTION_LOCK_CHECK_FUNCTION == 1 )		
					getcloselockerrcode(&vehicle_data,&mcu_send_data_st.lockerr);
					if(mcu_send_data_st.lockerr != 0)
					{
						ctlock_msg.lock_err = mcu_send_data_st.lockerr;
						ctlock_msg.lock_res.respondcmd = mcu_send_data_st.respondcmd;
						ctlock_msg.lock_res.respondsn = mcu_send_data_st.respondsn;
						ctlock_msg.lock_res.respondsta = 1;
						ctlock_msg.lock_type = mcu_send_data_st.send_type;
						if((ctlock_msg.lock_type == 0x83) || (ctlock_msg.lock_type == 0x63))
						{
							ret = bluetooth_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","bt_ctlock_res_queue_put  fail!\r\n");
							}
							ret = pdFAIL;	
						}
						else if((ctlock_msg.lock_type == 0x22) || (ctlock_msg.lock_type == 0x28))
						{
							ret = mangpatio_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","mangpatio_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						}
						else
						{
							ret = national808_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","national808_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							wakeup_source_set( POWER_NET );
						}
						// if((mcu_send_data_st.send_type < 0x30))
						// {
						// 	wakeup_source_set( POWER_NET );
						// 	mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						// }
						vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
						
						memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
					}
					else if((vehicle_data.lock&0x01) == 0)
					{
						mcu_send_data_st.lockerr = 0;
						ctlock_msg.lock_err = mcu_send_data_st.lockerr;
						ctlock_msg.lock_res.respondcmd = mcu_send_data_st.respondcmd;
						ctlock_msg.lock_res.respondsn = mcu_send_data_st.respondsn;
						ctlock_msg.lock_res.respondsta = 0;
						ctlock_msg.lock_type = mcu_send_data_st.send_type;
						if((mcu_send_data_st.send_type == 0x83) || (mcu_send_data_st.send_type == 0x63))
						{
							ret = bluetooth_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","bt_ctlock_res_queue_put  fail!\r\n");
							}
							ret = pdFAIL;	
						}
						else if((mcu_send_data_st.send_type == 0x22) || (mcu_send_data_st.send_type == 0x28))
						{
							ret = mangpatio_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","mangpatio_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						}
						else
						{
							ret = national808_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","national808_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							wakeup_source_set( POWER_NET );
						}
						// if(mcu_send_data_st.send_type < 0x30)
						// {
						// 	wakeup_source_set( POWER_NET );
						// 	mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						// }
						if((mcu_send_data_st.send_type == 0x08) || (mcu_send_data_st.send_type == 0x63) || (mcu_send_data_st.send_type == 0x28))
						{
							vehiclect_runing_state_set(CARCTL_RUNING_RELAY);	
						}
						else
						{
							vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
						}
						//gaoz_power_man_wakeup_task_num_stop(); /*wake up*/
						memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
						gaoz_log_debug_printf(INFOR_MODE,"mcar","vehicle_data.lock&0x01) == 0\r\n");
					}
				#else
					if((vehicle_data.lock&0x01) == 0)
					{ 
						// vehicle_info_report_semaphore_put();//主动上报一条0504
						
						mcu_send_data_st.lockerr = 0;
						ctlock_msg.lock_err = mcu_send_data_st.lockerr;
						ctlock_msg.lock_res.respondcmd = mcu_send_data_st.respondcmd;
						ctlock_msg.lock_res.respondsn = mcu_send_data_st.respondsn;
						ctlock_msg.lock_res.respondsta = 0;
						ctlock_msg.lock_type = mcu_send_data_st.send_type;
						if((mcu_send_data_st.send_type == 0x83) || (mcu_send_data_st.send_type == 0x63))
						{
							ret = bluetooth_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","bt_ctlock_res_queue_put  fail!\r\n");
							}
							ret = pdFAIL;	
						}
						else if((mcu_send_data_st.send_type == 0x22) || (mcu_send_data_st.send_type == 0x28))
						{ 
							ret = mangpatio_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","mangpatio_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						}
						else
						{
							ret = national808_ctlock_res_queue_put(&ctlock_msg);
							if(ret < 1)
							{
								gaoz_log_debug_printf(INFOR_MODE,"mcar","national808_ctlock_res_queue_put 0563 fail!\r\n");
							}
							ret = pdFAIL;
							wakeup_source_set( POWER_NET );
						}
						// if(mcu_send_data_st.send_type < 0x30)
						// {
						// 	wakeup_source_set( POWER_NET );
						// 	mangpatio_sleep_wakeup_state_set( SLEEP_STATE_NET );
						// }
						if((mcu_send_data_st.send_type == 0x08) || (mcu_send_data_st.send_type == 0x63) || (mcu_send_data_st.send_type == 0x28))
						{
							vehiclect_runing_state_set(CARCTL_RUNING_RELAY);	
						}
						else
						{
							vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
						}
						//gaoz_power_man_wakeup_task_num_stop(); /*wake up*/
						memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
						gaoz_log_debug_printf(INFOR_MODE,"mcar","vehicle_data.lock&0x01) == 0\r\n");
					}
				#endif
				}
				gaoz_power_man_wakeup_task_num_stop(); /*wake up*/
			}
		break;
		case CARCTL_RUNING_OTA:
			send_data[0] = mcu_send_data_st.send_type;
			u32toHex4(mcu_send_data_st.total,&send_data[1]);
			if(mcu_send_data_st.send_cnt ++ < 3)
			{
				ret = sendto_mcu_info(0x1050,(uint8_t *)TERM_ID,send_data,5);
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1050: %d\r\n",ret);
				if(ret == pdPASS)
				{
					*send_st = MCU_SEND_OK;
					*recv_st = MCU_HAVE_RESPONSE;
				}
			}
			else
			{
				vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
				memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1050 overtime\r\n");
			}
		break;
		case CARCTL_RUNING_CKVER:
			if(mcu_send_data_st.send_cnt ++ < 3)
			{
				ret = sendto_mcu_info(0x1013,(uint8_t *)TERM_ID,NULL,0);
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1013: %d\r\n",ret);
				if(ret == pdPASS)
				{
					*send_st = MCU_SEND_OK;
					*recv_st = MCU_HAVE_RESPONSE;
				}
				else
				{
					log_debug_printf(ERROR_MODE,VEH_CTRL_NAME ,"[%s]get mcu version fail\r\n",sys_err_infor_pointer_get( 57 ));
				}
			}
			else
			{
				vehiclect_runing_state_set(CARCTL_RUNING_CKCARST);//	
				memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1013 overtime\r\n");
			}
		break;
		case CARCTL_RUNING_RELAY:
			gaoz_power_man_wakeup_task_num_run();  /*wake up*/ 
			if(mcu_send_data_st.send_cnt ++ < 2)
			{
			#if 0
				uint8_t rlyDa[3] = {0};
				ret = file_termpara_read(RELAYPARA,(INT8 *)rlyDa);
				if(ret == 0)
			#endif
				/*读取继电器状态，由以前FLASH中读取方式修改为寄存器方式无需L610对状态进行存储，
				频繁读写L610文件系统出现异常，2022.06.16 YXX*/
				uint8_t rlyDa = 0;
				ret = readrelay_sta( (uint8_t *)&rlyDa );
				if( ret == pdPASS )
				{
					//if(((rlyDa[1] == 0x02) && (get_vehicleAcc_st() == 0x00)) ||(rlyDa[1] == 0x01))
					if( (rlyDa == 0x02) || (rlyDa == 0x01) )
					{
						ret = sendto_mcu_info(0x1032,(uint8_t *)TERM_ID,&rlyDa,1);
						gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1032 rlyda: %d\r\n",rlyDa);
						if(ret == pdPASS)
						{
							*send_st = MCU_SEND_OK;
							*recv_st = MCU_HAVE_RESPONSE;
						}
					}
					else
					{
						vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
						memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
						gaoz_log_debug_printf(INFOR_MODE,"mcar","1032-02-ACC\r\n");
					}
				}
			}
			else
			{
				vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
				memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1032overtime\r\n");
			}
			gaoz_power_man_wakeup_task_num_stop(); /*wake up*/
		break;
		case CARCTL_RUNING_CKCARST:
			if(mcu_send_data_st.send_cnt ++ < 3)
			{
				locktype = 0x01;
				ret = sendto_mcu_info(0x1017,(uint8_t *)TERM_ID,&locktype,1);
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1017: %d\r\n",ret);
				if(ret == pdPASS)
				{
					*send_st = MCU_SEND_OK;
					*recv_st = MCU_HAVE_RESPONSE;
				}
			}
			else
			{
				vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
				memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1017 overtime\r\n");
			}
		break;
		case CARCTL_RUNING_WIND:
			if(( national808_ctlock_queue_get( &ctlock_msg , 200 ) == pdPASS ) ||
			   ( mangpatio_ctlock_queue_get ( &ctlock_msg , 200) == pdPASS) )
			{	
				gaoz_log_debug_printf(INFOR_MODE,"mcar","ctlock_msg : %d\r\n",ctlock_msg.lock_type);
				locktype = ctlock_msg.lock_type;
				
				ret = sendto_mcu_info(0x10A5,(uint8_t *)TERM_ID,&locktype,1);
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info : %d\r\n",ret);
				if(ret == pdPASS)
				{
					*send_st = MCU_SEND_OK;
					*recv_st = MCU_HAVE_RESPONSE;
				}
				else
				{

				}

			}
			vehiclect_runing_state_set(CARCTL_RUNING_INIT);		
		break;
		case CARCTL_RUNING_SETODO:
			if(mcu_send_data_st.send_cnt ++ < 3)
			{
				send_len = warmcarled_net_data_read( send_data );
				ret = sendto_mcu_info(0x10A2,(uint8_t *)TERM_ID,send_data,send_len );
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 10A2: ret = %d,cnt = %d\r\n",ret, mcu_send_data_st.send_cnt );
				if(ret == pdPASS)
				{
					*send_st = MCU_SEND_OK;
					*recv_st = MCU_HAVE_RESPONSE;
				}
			}
			else
			{
				warmcarled_net_data_clear();
				vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
				memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 10A2 overtime\r\n");
			}
		break;
		case CARCTL_RUNING_STARTPOWER:
			if(mcu_send_data_st.send_cnt ++ < 3)
			{
				send_len = vehicle_engine_start_st_get( send_data );
				ret = sendto_mcu_info(0x10A6,(uint8_t *)TERM_ID,send_data,send_len );
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 10A6: ret = %d,cnt = %d\r\n",ret, mcu_send_data_st.send_cnt );
				if(ret == pdPASS)
				{
					*send_st = MCU_SEND_OK;
					*recv_st = MCU_HAVE_RESPONSE;
				}
			}
			else
			{
				vehicle_engine_start_st_clean();
				vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
				memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 10A6 overtime\r\n");
			}
		break;
		case CARCTL_RUNING_FUALT_CODE_QUERY:
			if( mcu_send_data_st.send_cnt ++ < 3)
			{
				send_data[0] = 0x02;
				ret = sendto_mcu_info(0x1081,(uint8_t *)TERM_ID,send_data, 1 );
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1081 query: ret = %d,cnt = %d\r\n",ret, mcu_send_data_st.send_cnt );
				if(ret == pdPASS)
				{
					*send_st = MCU_SEND_OK;
					*recv_st = MCU_HAVE_RESPONSE;
				}
			}
			else
			{
				vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
				memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1081 query overtime\r\n");
			}
		break;
		case CARCTL_RUNING_FUALT_CODE_CLEAR:
			if( mcu_send_data_st.send_cnt ++ < 3)
			{
				send_data[0] = 0x01;
				ret = sendto_mcu_info(0x1081,(uint8_t *)TERM_ID,send_data, 1 );
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1081 clear: ret = %d,cnt = %d\r\n",ret, mcu_send_data_st.send_cnt );
				if(ret == pdPASS)
				{
					*send_st = MCU_SEND_OK;
					*recv_st = MCU_HAVE_RESPONSE;
				}
			}
			else
			{
				vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
				memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1081 clear overtime\r\n");
			}
		break;
		case CARCTL_RUNING_MAINTENANCE_INFOR_SET:
			if( get_vehicleAcc_st() == 0x01 )	/*设置保养信息时*/
			{
				if(mcu_send_data_st.send_cnt ++ < 3)
				{
					send_len = vehicle_maintenance_infor_get( send_data );
					ret = sendto_mcu_info(0x1083,(uint8_t *)TERM_ID,send_data,send_len );
					gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1083: ret = %d,cnt = %d\r\n",ret, mcu_send_data_st.send_cnt );
					if(ret == pdPASS)
					{
						*send_st = MCU_SEND_OK;
						*recv_st = MCU_HAVE_RESPONSE;
					}
				}
				else
				{
					vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
					memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
					gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1083 overtime\r\n");
				}
			}
			else
			{
				maintain_set = 0x01;
				vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
				memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
				gaoz_log_debug_printf(INFOR_MODE,"mcar","ACC OFF disables the setting of maintenance information\r\n");
			}
		break;
		case CARCTL_RUNING_INIT:
			/*判断SIM卡状态，对SIM卡进行切换*/
			if((event_input_data_get(EVENT_SIMCARD) == 1) && (mcu_send_data_st.switch_sim != 1))
			{
				ret = sendto_mcu_info(0x1061,(uint8_t *)TERM_ID,NULL,0);
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1061: %d\r\n",ret);
				if(ret == pdPASS)
				{
					*send_st = MCU_SEND_OK;
					*recv_st = MCU_HAVE_RESPONSE;
					mcu_send_data_st.switch_sim = 1;
				}
			}
			/*判断保养信息设置状态位是否置1，同时ACC处于启动状态时。*/
			if(( maintain_set == 0x01 ) && ( get_vehicleAcc_st() == 0x01 ))
			{
				maintain_set = 0;
				vehiclect_runing_state_set(CARCTL_RUNING_MAINTENANCE_INFOR_SET);/*保养信息设置*/
			}
		break;
		case CARCTL_RUNING_KEY_INFOR_SET:
			send_len = vehicle_key_infor_get( send_data );
			if( send_len != 0 )
			{
				sendto_mcu_info(0x1084,(uint8_t *)TERM_ID,send_data,send_len );
			}
			vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
		break;
		case CARCTL_RUNING_RV_POWER_CTL:
			if( mcu_send_data_st.send_cnt ++ < 3)
			{
				send_data[0] = vehicle_rv_power_control; /*电源控制寄存器*/
				ret = sendto_mcu_info(0x1085,(uint8_t *)TERM_ID,send_data, 1 );
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1085 power control: ret = %d,cnt = %d\r\n",ret, mcu_send_data_st.send_cnt );
				if(ret == pdPASS)
				{
					*send_st = MCU_SEND_OK;
					*recv_st = MCU_HAVE_RESPONSE;
				}
			}
			else
			{
				vehiclect_runing_state_set(CARCTL_RUNING_INIT);	
				memset(&mcu_send_data_st, 0, sizeof(mcu_send_data_st_t));
				gaoz_log_debug_printf(INFOR_MODE,"mcar","sendto_mcu_info 1085 power control overtime\r\n");
			}
		break;
        default:
        	break;
	}
	
	return ret;
}

/** ****************************************************************************
* @remarks       void national_data_analytic_fun( mcu_res_msg_t *nat_res)
* @brief         接收响应分析
* @param[in]     *nat_res 应答结果
* @param[out]    无
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
static void mcu_data_analytic_fun( mcu_res_msg_t *net_res)
{
	switch( net_res->commane )
	{	
		case MCU_RESPONSE_LOCK_UNLOCK:		
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_WAIT );
			}
			else
			{	
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			mcu_send_data_st.send_cnt = 0;
		break;
		
		case MCU_RESPONSE_SPEAK_LIGHT:		
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			else
			{	
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
		break;		
		case MCU_RESPONSE_OTA:
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_UPGRADE );
			}
			else
			{	
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			mcu_send_data_st.send_cnt = 0;
		break;
		case MCU_RESPONSE_CKVER:
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_CKCARST );//
			}
			else
			{	
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );//
			}
			mcu_send_data_st.send_cnt = 0;
		break;
		case MCU_RESPONSE_RELAY:
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			else
			{	
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			mcu_send_data_st.send_cnt = 0;
		break;
		case MCU_RESPONSE_CKCARST:
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			else
			{	
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			mcu_send_data_st.send_cnt = 0;
		break;
		case MCU_RESPONSE_SWSIM:
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
				mcu_send_data_st.switch_sim = 0;//切卡成功
				event_input_data_set(EVENT_SIMCARD , 2);
			}
			else
			{	
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
		break;
		case MCU_RESPONSE_WIND:
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			else
			{	
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
		break;
		case MCU_RESPONSE_SETODO:
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			else
			{	
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			mcu_send_data_st.send_cnt = 0;
			warmcarled_net_data_clear();
		break;
		case MCU_RESPONSE_STARTPOWER:
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			else
			{	
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			mcu_send_data_st.send_cnt = 0;
			vehicle_engine_start_st_clean();
		break;
		case MCU_RESPONSE_FUALT_CODE:
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			else
			{	
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			mcu_send_data_st.send_cnt = 0;
		break;
		case MCU_RESPONSE_MAINTENANCE_INFOR:
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			else
			{	
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			mcu_send_data_st.send_cnt = 0;
		break;
		case MCU_RESPONSE_RV_POWER_CTL:
			if( net_res->results == pdPASS )
			{
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			else
			{
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
			}
			mcu_send_data_st.send_cnt = 0;
		break;
        default:
            break;
	}
} 
/** ****************************************************************************
* @remarks       static uint32_t vehicle_ctrl_wait_response_result( uint32_t wait_time )
* @brief         控车等待结果
* @param[in]     wait_time 延时的时间设置 单位ms
* @param[out]    无
* @return        pdPASS 成功 pdFAIL 失败
* @attention     无
*******************************************************************************/
static uint32_t vehicle_ctrl_wait_response_result( uint32_t wait_time )
{
	uint32_t ret = pdFAIL;
	mcu_res_msg_t ct_res_msg;

	if( mcu_send_res_queue_get( &ct_res_msg , wait_time ) == pdPASS )
	{	/* 解析数据应答的结果 */
		gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_get %d,%d\r\n",ct_res_msg.commane,ct_res_msg.results);	
		mcu_data_analytic_fun( &ct_res_msg );
		ret = ct_res_msg.results;
	}
	else
	{
		gaoz_log_debug_printf(INFOR_MODE,"mcar","mcu_send_res_queue_get fail\r\n");	
		ret = pdFAIL;
	}
	return ret;
}
/** ****************************************************************************
* @remarks       static uint32_t vehicle_time_delay( uint32_t wait_time )
* @brief         等待延时功能
* @param[in]     wait_time 延时的时间设置 单位ms
* @param[out]    无
* @return        pdPASS 成功 pdFAIL 失败
* @attention     无
*******************************************************************************/
static uint32_t vehicle_time_delay( uint32_t wait_time )
{
	uint32_t ret = pdFAIL;
	static uint32_t running_st_ovcnt = 0;
	ota_mcu_notify_t res_msg;
	if ( vehiclect_runing_state_get() == CARCTL_RUNING_INIT )
	{
		running_st_ovcnt = 0;
		if( ota_mcu_notify_queue_get( &res_msg , wait_time ) == pdPASS )
        {  
			mcu_send_data_st.send_type = res_msg.upgrade_flag;
			mcu_send_data_st.total = res_msg.upgrade_total;
            vehiclect_runing_state_set( CARCTL_RUNING_OTA );
            ret = pdPASS;
        }
	}
	else
	{	
		if((vehiclect_runing_state_get() == CARCTL_RUNING_LOCK_UNLOCK) ||
		 (vehiclect_runing_state_get() == CARCTL_RUNING_SPEAK_LIGHT) ||
		(vehiclect_runing_state_get() == CARCTL_RUNING_WAIT))
		{
			if(running_st_ovcnt++ > 15*1000/wait_time)
			{
				running_st_ovcnt = 0;
				vehiclect_runing_state_set( CARCTL_RUNING_INIT );
				gaoz_log_debug_printf(INFOR_MODE,"mcar","%s,%d running_st_ovcnt > 10s", __FUNCTION__, __LINE__);
			}
		}
		gaoz_task_sleep( wait_time );
	}
	return ret;
}
/** ****************************************************************************
* @remarks       INT32 getfile_from_http(ota_mcu_request_t *req_msg)
* @brief         提取文件并发送升级包
* @param[in]     *req_msg属性
* @param[out]    无
* @return        pdPASS 成功 pdFAIL 失败
* @attention     无
*******************************************************************************/
INT32 getfile_from_http(ota_mcu_request_t *req_msg)
{
    INT32 fd = 0;
    INT32 ret = pdFAIL;
	INT32 getlen = 0;
	INT32 file_offset = 0;

	if(req_msg == NULL)
	{
		return ret;
	}

    uint8_t *pt = (uint8_t *)gaoz_fibo_malloc(1024*2);
    if (pt == NULL)
    {
        return ret;
    }

    fd = fibo_file_open(MCU_HTTP_FILE, O_RDWR);
    if(fd == -1)
    {
        gaoz_log_debug_printf(INFOR_MODE,"mcar","%s,%d http file read error", __FUNCTION__, __LINE__);
        fibo_file_close(fd);
        gaoz_fibo_free(pt);
        return ret;
    }
	if(req_msg->req_curnum == req_msg->req_total)
	{
		file_offset = fibo_file_seek(fd,-(req_msg->req_length),FS_SEEK_END); 
		if(file_offset < 0)
		{
			OSI_LOGI(0, "fibo_file_seek fail");
			fibo_file_close(fd);
			gaoz_fibo_free(pt); 
			ret = pdFAIL;
			return ret;
		}
	}
	else
	{
		file_offset = fibo_file_seek(fd,(req_msg->req_curnum-1)*req_msg->req_length,FS_SEEK_SET); 
		if(file_offset < 0)
		{
			OSI_LOGI(0, "fibo_file_seek fail");
			fibo_file_close(fd);
			gaoz_fibo_free(pt); 
			ret = pdFAIL;
			return ret;
		}
	}
    gaoz_log_debug_printf(INFOR_MODE,"mcar","offset %d ", file_offset);	
	memset(pt,0,1024*2);
	pt[0] = (uint8_t)(req_msg->req_curnum >> 8);
	pt[1] = (uint8_t)(req_msg->req_curnum & 0xff);
	pt[2] = (uint8_t)(req_msg->req_length >> 8);
	pt[3] = (uint8_t)(req_msg->req_length & 0xff);

	getlen = fibo_file_read(fd, &pt[4], req_msg->req_length);
    if(getlen < 0)
    {
        gaoz_log_debug_printf(INFOR_MODE,"mcar","%s,%d http file read error", __FUNCTION__, __LINE__);
        fibo_file_close(fd);
        gaoz_fibo_free(pt);
        return ret;
    }
    gaoz_log_debug_printf(INFOR_MODE,"mcar","offset %d data %s\r\n", file_offset,pt);
    gaoz_log_debug_printf(INFOR_MODE,"mcar","%d cur number,%d total", req_msg->req_curnum,req_msg->req_total);
	ret = sendto_mcu_info(0x1051,(uint8_t *)TERM_ID,pt,(req_msg->req_length+4));
	if(ret != pdPASS)
	{
		return ret;
	}
	
	ret = pdPASS;

	return ret;
}
/** ****************************************************************************
* @remarks       static uint32_t vehicle_ota_manage_fun( void )
* @brief         升级MCU 
* @param[in]     无
* @param[out]    无
* @return        pdPASS 成功 pdFAIL 失败
* @attention     无
*******************************************************************************/
static uint32_t vehicle_ota_manage_fun( void )
{
	uint32_t ret = pdFAIL;
	ota_mcu_request_t req_msg;
	static int8_t waitovtm = 0;

	for(;;)
	{
		gaoz_mon_reset_task_dog(); /*系统喂狗操作*/
		if( ota_mcu_request_queue_get(&req_msg,1000) == pdPASS)
		{
			if(getfile_from_http(&req_msg) == pdPASS)
			{
				waitovtm = 0;
			}
		}
		else
		{
			if(waitovtm ++ > 10)
			{
				waitovtm = 0;
				gaoz_log_debug_printf(INFOR_MODE,"mcar","vehicle_ota_manage_fun overtime \r\n"); 
				break;	
			}
		}
	}

	return ret;
}
/** ****************************************************************************
* @remarks       uint32 vehicle_set_vin(uint8_t *newvin)
* @brief         设置新的VIN
* @param[in]     新设置的VIN
* @param[out]    无
* @return        pdFAIL失败 pdPASS成功
* @attention     无
*******************************************************************************/
uint32 vehicle_set_vin(uint8_t *newvin)
{
	uint32_t ret = pdFAIL;
	vehicle_save_data_t readinfo;
  
	if( vin_data_verification( (char *)newvin) == pdPASS )
	{ 
		memcpy(current_data.vin,newvin,17);
		gaoz_save_vin_data_infor_write((uint8_t*)&current_data,sizeof(vehicle_save_data_t)); 
		gaoz_log_debug_printf(INFOR_MODE,"mcar","set  vin write suc:%s  ",newvin);
	}

	memset(&readinfo,0,sizeof(vehicle_save_data_t));
	gaoz_save_vin_data_infor_read(&readinfo,sizeof(vehicle_save_data_t));
	
	gaoz_log_debug_printf(INFOR_MODE,"mcar","set  vin:%s  ",newvin);	
	gaoz_log_debug_printf(INFOR_MODE,"mcar","readinfo.vin:%s  ",readinfo.vin);	
	if(memcmp(vehicle_data.vin,readinfo.vin,17) != 0x00)
	{
		gaoz_log_debug_printf(INFOR_MODE,"mcar","TE_RUNING_AUTH          vin:%s  ",newvin);	
		gaoz_log_debug_printf(INFOR_MODE,"mcar","TE_RUNING_AUTH readinfo.vin:%s  ",readinfo.vin);	

		memcpy(vehicle_save_data.vin,readinfo.vin,17);
		memcpy(vehicle_data.vin,newvin,17);
		memcpy(vehicle_data_old.vin,vehicle_data.vin,17);

		if( vehicle_authentication_mangatio_st_get() != VEHICLE_AUTH_REQ )
		{
			vehicle_authentication_mangatio_st_set( VEHICLE_AUTH_REQ );
		} 
		national808_net_ctrl_infor_set( TER_RUNING_AUTH );
		
		ret = pdPASS;
	} 

	if( (memcmp(newvin,vehicle_data.vin,17) != 0) )
	{  
		if( (vin_data_verification( (char *)newvin) == pdPASS) 
		&&	(newvin[0]  != '0')	
		&&  (newvin[1]  != '0')	
		&&  (newvin[2]  != '0'))	
		{
			memcpy(vehicle_data.vin,newvin,17);
		}		  	
	}



	return ret;
}

/******************************************************************************
* @remarks       uint8_t vehicle_vin_get(uint8_t *da)
* @brief         获取车辆VIN 
* @param[in]     获取VIN的存储地址
* @param[out]    
* @return        获取的有效字节长度
* @attention     无
*******************************************************************************/
uint8_t vehicle_vin_get(uint8_t *da)
{
	uint8_t ret = pdFAIL;
	vehicle_save_data_t vehicle_save_info;

	if(da == NULL)
	{
		return ret;
	}

	if(gaoz_save_vin_data_infor_read( (uint8_t *)&vehicle_save_info, sizeof(vehicle_save_data_t) ) == pdPASS )
	{
		if( (vin_data_verification( (char *)vehicle_save_info.vin) == pdPASS) 
		&&	(vehicle_save_info.vin[0]  != '0'))	
		{
			gaoz_log_debug_printf(INFOR_MODE,"mcar","get flash vin:%s  ",vehicle_save_info.vin);	
			memcpy(da,vehicle_save_info.vin,17);
			ret = pdPASS;
		} 
		else 
		{
			if( (vin_data_verification( (char *)vehicle_data.vin) == pdPASS )
			&&	(vehicle_data.vin[0]  != '0')	 )	
			{
				gaoz_log_debug_printf(INFOR_MODE,"mcar","get vehicle vin:%s  ",vehicle_save_info.vin);
				memcpy(da,vehicle_data.vin,17); 
				ret = pdPASS;
			} 
			else  
			{
				gaoz_log_debug_printf(INFOR_MODE,"mcar","get vehicle err:%s  ",da);
			}
		}
	}
	else
	{
		if( (vin_data_verification( (char *)vehicle_data.vin) == pdPASS )
		&&	(vehicle_data.vin[0]  != '0')	 )	
		{
			gaoz_log_debug_printf(INFOR_MODE,"mcar","get vehicle vin:%s  ",vehicle_save_info.vin);
			memcpy(da,vehicle_data.vin,17); 
			ret = pdPASS;
		} 
		else 
		{
			gaoz_log_debug_printf(INFOR_MODE,"mcar","get vehicle err:%s  ",da);
		}
	}
	
	return ret;
}

/** ****************************************************************************
* @remarks       static uint32_t vehicle_data_change_get( n808_vehicle_data_t *data_vehicle)
* @brief         车身数据变化而上报位置信息
* @param[in]     * data_vehicle车身数据
* @param[out]    无
* @return        pdFAIL失败 pdPASS成功
* @attention     无
*******************************************************************************/
static uint32_t vehicle_data_change_get( n808_vehicle_data_t *data_vehicle)
{
	uint8_t report = 0;
	uint8_t txbuf[128]={0};
	int ret = 0;
    int txbuflen=0;
	static uint16_t shake_repcnt = 0;
	//national_run_state_e run_st;
	//gsen_bmi160_body_state_e gsen_st;
	uint8_t sys_power=0,veh_power=0;
	gnss_info_struct gnss_info;
	static uint8_t gnss_info_pos_flag = 0;
	uint8_t tire_data[10] = { 0 },tire_size = 0;

	if((data_vehicle == NULL)||
		(memcmp(taginf.ManageID,"\x0\x0\x0\x0\x0\x0",6) == 0))
	{
		return pdFAIL;
	}
		
	if(vehicle_data_old.doors_status != data_vehicle->doors_status )
	{
		vehicle_data_old.doors_status = data_vehicle->doors_status;
		report = 1;
	}
	if(vehicle_data_old.lights_status != ((data_vehicle->lights_status)&0x3f) )//无雾灯
	{
		vehicle_data_old.lights_status = (data_vehicle->lights_status)&0x3f;
		report = 1;

	}
	if(vehicle_data_old.win_status != data_vehicle->win_status )
	{
		vehicle_data_old.win_status = data_vehicle->win_status;
		report = 1;
	}
	if(vehicle_data_old.lock != data_vehicle->lock )
	{
		vehicle_data_old.lock = data_vehicle->lock;
		report = 1;
	}
	if(vehicle_data_old.brake_gear != ((data_vehicle->brake_gear)&0xFD))
	{

		vehicle_data_old.brake_gear = (data_vehicle->brake_gear)&0xFD;
		report = 1;

		if((vehicle_data_old.brake_gear&0x08) == 0x08)//R
		{
			event_input_data_set(EVENT_DIRECTION,2);
		}
		else if((vehicle_data_old.brake_gear&0x20) == 0x20) //D
		{
			event_input_data_set(EVENT_DIRECTION,1);
		}
		else
		{
			event_input_data_set(EVENT_DIRECTION,0);
		}
	}
	if(((vehicle_data_old.Ignition_status)&0x0A) != ((data_vehicle->Ignition_status)&0x0A) )
	{
		vehicle_data_old.Ignition_status = data_vehicle->Ignition_status;
		report = 1;
		if((vehicle_data_old.Ignition_status & 0x0A) != 0)
		{
			//can_work_st_set(CAN_WORK_ST_START);
			event_input_data_set(EVENT_ENGINE,1);
		}
		else
		{
			//can_work_st_set(CAN_WORK_ST_STOP);
			event_input_data_set(EVENT_ENGINE,0);
		}
	}
	if(vehicle_data_old.Charge_status != data_vehicle->Charge_status )
	{
		vehicle_data_old.Charge_status = data_vehicle->Charge_status;
		report = 1;
	}
	if(vehicle_data_old.other_status != data_vehicle->other_status )
	{
		vehicle_data_old.other_status = data_vehicle->other_status;
		report = 1;//AC 安全带 
	}
	if(vehicle_data_old.relay_sta != data_vehicle->relay_sta)
	{
		vehicle_data_old.relay_sta = data_vehicle->relay_sta;
		report = 1;
	}
	//VIN
	//if((memcmp(vehicle_data_old.vin,data_vehicle->vin,17) != 0) &&
	//  (data_vehicle->vin[0] != 0) && (data_vehicle->vin[16] != 0))
	// if( vin_data_verification( (char *)data_vehicle->vin) == pdPASS )
	// {
	// 	if( (memcmp(vehicle_data_old.vin,data_vehicle->vin,17) != 0) )
	// 	{
			 
	// 		if( vehicle_authentication_mangatio_st_get() != VEHICLE_AUTH_REQ )
	// 		{
	// 			vehicle_authentication_mangatio_st_set( VEHICLE_AUTH_REQ );
	// 		}
	// 		national808_net_ctrl_infor_set( TER_RUNING_AUTH );
	// 		memcpy(vehicle_data_old.vin,data_vehicle->vin,17);
	// 		gaoz_save_vin_data_infor_write( (uint8_t *)data_vehicle->vin, 17 );
	// 	}
	// #if 0
	// 	run_st = national808_net_runing_state_get();
	// 	if(run_st == TER_RUNING_DATA)
	// 	{
	// 		national808_net_runing_state_set(TER_RUNING_AUTH);
	// 		memcpy(vehicle_data_old.vin,data_vehicle->vin,17);
	// 	}
	// #endif
	// }
	//MCU VERSION
	if(memcmp(mcu_version_old,get_mcuversion(),S_VER_LEN) != 0)
	{
		// if( vehicle_authentication_st_get() != VEHICLE_AUTH_REQ )
		// {
		// 	vehicle_authentication_st_set( VEHICLE_AUTH_REQ );
		// }
		if( vehicle_authentication_mangatio_st_get() != VEHICLE_AUTH_REQ )
		{
			vehicle_authentication_mangatio_st_set( VEHICLE_AUTH_REQ );
		} 	
		national808_net_ctrl_infor_set( TER_RUNING_AUTH );
		memcpy(mcu_version_old,get_mcuversion(),S_VER_LEN);
		#if 0
		static uint8_t mcu_vercnt = 0;
		run_st = national808_net_runing_state_get();
		if(run_st == TER_RUNING_DATA)
		{
			if(++mcu_vercnt > 30) //3s
			{
				mcu_vercnt = 0;
				national808_net_runing_state_set(TER_RUNING_AUTH);
				if(strlen((char *)mcu_version_old) != 0)
				{
					gaoz_soft_reset();
				}
				memcpy(mcu_version_old,get_mcuversion(),S_VER_LEN);
			}
		}
		else
		{
			mcu_vercnt = 0;
		}
		#endif
	}
	
	if((data_vehicle->speed != 0) && (vehicle_data_old.speed != data_vehicle->speed))
	{
		vehicle_data_old.speed = data_vehicle->speed;
		event_input_data_set(EVENT_SPEED,(data_vehicle->speed)/10);//km/h
	}
	else if(data_vehicle->speed == 0)
	{
		#if USERSPEED_FROM_GPS
		static uint16_t get_gpsspd = 0;
		gnss_info_struct gnss_info = {0};
		if(++get_gpsspd > 20) //2s
		{
			gaoz_gnss_info_now_get( &gnss_info );
			event_input_data_set(EVENT_SPEED,gnss_info.gnss_position_info.speed);
			get_gpsspd = 0;
		}
		else
		{
			if((event_input_data_get(EVENT_ENGINE) == 0) && 
				(event_input_data_get(EVENT_SPEED) != 0))
			{
				get_gpsspd = 0;
				event_input_data_set(EVENT_SPEED,0);
			}
		}
		#else
		event_input_data_set(EVENT_SPEED,0);
		#endif
	}
	if((data_vehicle->bat_vol != 0) && (vehicle_data_old.bat_vol != data_vehicle->bat_vol))
	{
		vehicle_data_old.bat_vol = data_vehicle->bat_vol;
		event_input_data_set(EVENT_POWER,data_vehicle->bat_vol);
	}
	else if(data_vehicle->bat_vol == 0)
	{
		event_input_data_set(EVENT_POWER,0);
	}
	
	//振動
	if((vehicle_data_old.Ignition_status & 0x0A) == 0) /* stop */
	{
		/*gsen_st = gsen_sensor_body_st_get();
		if((gsen_st == GSEN_ATT_ST_SHAKE) && (gsen_st != gsen_oldst))
		{
			gsen_oldst = gsen_st; 
			report = 1;
		}
		else if((gsen_st != GSEN_ATT_ST_SHAKE) && (gsen_st != gsen_oldst))
		{
			gsen_oldst = gsen_st; 
			report = 1;
		}*/	

		if(n808_gsen_st.car_shake == 1)
		{
			if(shake_repcnt == 0)
			{
				report = 1;
			}
			shake_repcnt ++;
			if(shake_repcnt > 300) //连续30s
			{
				shake_repcnt = 0;
				report = 1;
			}
		}
		else
		{
			if(shake_repcnt != 0)
			{
				shake_repcnt ++;
			}
			if(shake_repcnt > 300) //连续30s
			{
				shake_repcnt = 0;
			}
		}		
	}
	if(n808_gsen_st.car_crash == 1)
	{
		report = 1;
	}
	if(n808_gsen_st.car_rollover == 1)
	{
		report = 1;
	}
	//掉电或欠压
	sys_power = sys_hard_state_get(SYS_POWER);
	if(sys_power != sys_power_old)
	{
		sys_power_old = sys_power;
		report = 1;
	}
	veh_power = sys_hard_state_get(SYS_VEHICLE);
	if(veh_power != veh_power_old)
	{
		veh_power_old = veh_power;
		report = 1;
	}
	//定位状态
	gaoz_gnss_info_now_get( &gnss_info );
	if(gnss_info_pos_flag != gnss_info.gnss_position_info.pos_flag)
	{
		gnss_info_pos_flag = gnss_info.gnss_position_info.pos_flag;
		report = 1;
	}
#if 0
	/*查询保养信息状态，当检测数据有效时进行数据上报*/
	if( vehicle_maintenance_cfg_get( NULL ) == 0x01 )
	{
		national808_net_ctrl_infor_set( TER_RUNING_MAINTENANCE_INFOR_SEND );
		vehicle_maintenance_cfg_state_clean();
		// if(national808_net_runing_state_get() == TER_RUNING_DATA)
		// {
		// 	national808_net_runing_state_set( TER_RUNING_MAINTENANCE_INFOR_SEND );
		// 	vehicle_maintenance_cfg_state_clean();
		// }
	}
	/*查询读取的故障码状态，当数据有效时进行数据上报*/
	if( vehicle_fault_code_state == FAULE_CODE_READ )
	{
		national808_net_ctrl_infor_set( TER_RUNING_FAULT_CODE_INFOR_SEND );
		vehicle_fault_code_state = FAULE_CODE_INIT;
		// if(national808_net_runing_state_get() == TER_RUNING_DATA)
		// {
		// 	national808_net_runing_state_set( TER_RUNING_FAULT_CODE_INFOR_SEND );
		// 	vehicle_fault_code_state = FAULE_CODE_INIT;
		// }
	} 
#endif
	/*判断车辆类型状态，状态发送变化时上报网络数据*/
	if(vehicle_data_old.vehicle_type != data_vehicle->vehicle_type)
	{
		vehicle_data_old.vehicle_type = data_vehicle->vehicle_type;
		report = 1;
	}
	/*汽车胎压 胎温值判断，数据发生变换时数据上报*/
	tire_size = vehicle_tire_pressure_data_get( tire_data );
	if(memcmp(vehicle_data_old.vehicle_tire, tire_data,tire_size ) != 0)
	{
		memcpy(vehicle_data_old.vehicle_tire,tire_data,tire_size );
		report = 1;
	}
	/*上报状态设置为1时，数据进行上报*/
	if(report == 1)
	{ 
		make_vehicle_infor();

		report = 0;
		n808_gsen_st.gsen_alarm = 0;
	}

	return pdPASS;
}
/** ****************************************************************************
* @remarks      static void vehicle_portstatus_get( void *pv)
* @brief         获取port信息
* @param[in]     
* @param[out]    无
* @return        pdFAIL失败 pdPASS成功
* @attention     无
*******************************************************************************/
static uint32_t vehicle_portstatus_get( void *pv)
{
	uint8_t rDa = 0;
	uint32_t ret = pdFAIL;
    UINT32  adc0 = 0;
    UINT32  adc2 = 0;
    static   UINT32  adc0_old = 0;
    static   UINT32  adc2_old = 0;

    /*ADC*/ 
	adc0 = gaoz_port_adc_gpio_value_get(GET_ADC0);
    if(adc0_old != adc0)
    {
       if(abs(adc0_old-adc0) > 100)
       {
           rDa = 1;
       }
		adc0_old = adc0;
    }
    
	adc2 = gaoz_port_adc_gpio_value_get(GET_ADC2); 
    if(adc2_old != adc2)
    {
       if(abs(adc2_old-adc2) > 100)
       {
           rDa = 1;
       }
	   adc2_old = adc2;
    } 
    /*report*/
    if((rDa == 1) || (pv != NULL))
    {
        uint8_t dDa[9];
		
        dDa[0] = 0;
        dDa[1] = 0;
        dDa[2] = 0;
        dDa[3] = 0;
        dDa[4] = 0;
        dDa[5] = (UINT16)(adc0)>>8;
        dDa[6] = ((UINT16)(adc0)&0xff);
        dDa[7] = (UINT16)(adc2)>>8;
        dDa[8] = ((UINT16)(adc2)&0xff);                
       	ret = sendto_mcu_info(0x1011,(uint8_t *)TERM_ID,dDa,9);
		gaoz_log_debug_printf(DEBUG_MODE,"mcar","ADC0:%d,ADC2:%d\r\n",adc0,adc2);	   
		rDa = 0;
    }
	return ret;
}
/** ****************************************************************************
* @remarks       static uint8_t port_check_run_time( void )
* @brief         监控运行时间计数器
* @param[in]     无
* @param[out]    无
* @return        1 计数器溢出，0 计数器未溢出
* @attention     监控任务周期为100ms，其他时间检测需要1S钟进行检测一次。
*******************************************************************************/
static uint8_t port_check_run_time( void )
{
    port_counter ++;
    if( port_counter >= 10 )
    { 
        port_counter = 0;
        return 1;
    }
    return 0;
}
/** ****************************************************************************
* @remarks       static void  vehicle_ctrl_handle_task( void * pvParameters)
* @brief         控制处理任务
* @param[in]     * pvParameters 任务参数
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void  vehicle_ctrl_handle_task( void * pvParameters)
{ 
    ( void ) pvParameters;
	
	vehiclect_runing_st = CARCTL_RUNING_CKVER;
	mcu_send_res_queue_create();
	
	gaoz_mon_reg_task_dog( 60 * GAOZ_TICK_PERIOD_S ,(uint8_t * )VEH_CTRL_NAME, TASK_SEM_YES); /*注册任务看门狗*/
    for( ;; )
    { 
        gaoz_mon_reset_task_dog(); /*系统喂狗操作*/ 
		if( vehicle_ctrl_manage_fun(&mcu_send_data , &mcu_response ) == pdPASS )
        { 
		    if( mcu_send_data == MCU_SEND_OK )          /*发送数据成功*/
            {
                if( mcu_response == MCU_HAVE_RESPONSE ) /*等待应答*/
                {
                    if( vehicle_ctrl_wait_response_result( MCU_ACK_QUEUE_RX_DATA_TIME ) == pdPASS )
                    {   
                       log_debug_send(INFOR_MODE , NET_MAN_NAME ,"vehicle_ctrl_wait_response_result ok" ,0 );
                    }
                    else
                    {   

                    }
                }
            }
            else
            {
				gaoz_task_sleep(100);
            }
        }
		else
        {
            vehicle_time_delay(100);
        }
    }	
}

/** ****************************************************************************
* @remarks       static void  vehicle_data_handle_task( void * pvParameters)
* @brief         处理车机数据处理任务
* @param[in]     * pvParameters 任务参数
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void  vehicle_data_handle_task( void * pvParameters)
{ 
    ( void ) pvParameters;
    
    gaoz_mon_reg_task_dog( 60 * GAOZ_TICK_PERIOD_S ,(uint8_t * )VEH_MAN_NAME ,TASK_SEM_YES); /*注册任务看门狗*/
    for( ;; )
    { 
        gaoz_mon_reset_task_dog(); 	/*系统喂狗操作*/
        n808_data_to_save(&taginf);
		vehicle_data_change_get(&vehicle_data);
		if(port_check_run_time() == 1)
		{
			/* port */
			vehicle_portstatus_get(NULL);
			/*print*/
			print_to_mcu(&taginf);
			/*周期性鉴权*/
			vehicle_authentication_time_detection();
			/*周期性获取GNSS数据并进行保存*/
			vehicle_adas_position_read();	
		}
        gaoz_task_sleep(100);
		
    }
}
/** ****************************************************************************
* @remarks       static void  vehicle_ota_handle_task( void * pvParameters)
* @brief         处理ota处理任务
* @param[in]     * pvParameters 任务参数
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void  vehicle_ota_handle_task( void * pvParameters)
{
    ( void ) pvParameters;
	INT32 getsize = 0;
	ota_mcu_notify_queue_create();
    ota_mcu_request_queue_create();
    
    gaoz_mon_reg_task_dog( 60 * GAOZ_TICK_PERIOD_S ,(uint8_t * )VEH_OTA_NAME ,TASK_SEM_YES); /*注册任务看门狗*/
    for( ;; )
    {
        gaoz_mon_reset_task_dog(); /*系统喂狗操作*/
        if(vehicle_ota_sem_get() == pdPASS)
        {
			getsize = fibo_file_getSize(MCU_HTTP_FILE);
			if(getsize > 0)
			{
				ota_mcu_notify(getsize);
				vehicle_ota_manage_fun();
			}
			else
			{
				gaoz_log_debug_printf(ERROR_MODE,"mcar","/FFS/httpgd Size 0\r\n");		
				log_debug_printf(ERROR_MODE,VEH_CTRL_NAME ,"[%s]/FFS/httpgd Size fail\r\n",sys_err_infor_pointer_get( 58 ));
			}	
        }
    }
}

/** ****************************************************************************
* @remarks       uint8_t n808_gsen_sensor_state_get( void )
* @brief         获取gsen状态
* @param[in]     无
* @param[out]    无
* @return        报警状态
* @attention     无
*******************************************************************************/
uint8_t n808_gsen_sensor_state_get( void )
{
	return n808_gsen_st.gsen_alarm;
}

/** ****************************************************************************
* @remarks       static uint32_t n808_gsen_sensor_state_cb( )
* @brief         gsen状态回调函数
* @param[in]     st状态
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void n808_gsen_sensor_state_cb( uint32_t st)
{
	uint32_t	gsen_st;
	
	gsen_st = (uint32_t )st;
	//gaoz_log_debug_printf(DEBUG_MODE,"mcar","gsen_st:%d\r\n",gsen_st);	
	switch(gsen_st)
	{
		case GSEN_ATT_ST_CRASH:
			n808_gsen_st.car_crash = 1;
			break;
		case GSEN_ATT_ST_ROLLOVER:
			n808_gsen_st.car_rollover = 1;
			break;
		case GSEN_ATT_ST_SHAKE:
			n808_gsen_st.car_shake = 1;
			break;
		case GSEN_ATT_ST_SHIFTING:
			n808_gsen_st.car_shifting = 1;
			break;
		default:
			break;
	}
}

/** ****************************************************************************
* @remarks       vehicle_authentication_type_e vehicle_authentication_st_get( void )
* @brief         获取车辆鉴权状态
* @param[in]     无
* @param[out]    无
* @return        鉴权状态
* @attention     无
*******************************************************************************/
vehicle_authentication_type_e vehicle_authentication_st_get( void )
{
	return vehicle_authentication_st;
}

/** ****************************************************************************
* @remarks       void vehicle_authentication_st_set( vehicle_authentication_type_e type )
* @brief         设置车辆鉴权状态
* @param[in]     车辆鉴权的状态
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
void vehicle_authentication_st_set( vehicle_authentication_type_e type )
{
	vehicle_authentication_st = type;
}

/** ****************************************************************************
* @remarks       vehicle_authentication_type_e vehicle_authentication_mangatio_st_get( void )
* @brief         获取车辆鉴权状态
* @param[in]     无
* @param[out]    无
* @return        鉴权状态
* @attention     无
*******************************************************************************/
vehicle_authentication_type_e vehicle_authentication_mangatio_st_get( void )
{
	return vehicle_authentication_mangpatio_st;
}

/** ****************************************************************************
* @remarks       void vehicle_authentication_mangatio_st_set( vehicle_authentication_type_e type )
* @brief         设置车辆鉴权状态
* @param[in]     车辆鉴权的状态
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
void vehicle_authentication_mangatio_st_set( vehicle_authentication_type_e type )
{
	vehicle_authentication_mangpatio_st = type;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_engine_start_st_set( uint16_t sn, uint16_t id, uint8_t st )
* @brief         设置车辆一键启动控制状态
* @param[in]     sn 流水号，id ID，st 控制状态
* @param[out]    无
* @return        pdPASS 成功，pdFAIL 失败
* @attention     无
*******************************************************************************/
uint32_t vehicle_engine_start_st_set( uint16_t sn, uint16_t id, uint8_t st )
{
	uint32_t ret = pdFAIL;
	
	if( vehicle_engine_start_infor.st == 0x00 )
	{
		vehicle_engine_start_infor.sn = sn;
		vehicle_engine_start_infor.id = id;
		vehicle_engine_start_infor.st = st;
		ret = pdPASS;
	}
	
	return ret;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_engine_start_st_get( uint8_t *infor )
* @brief         获取车辆一键启动控制数据
* @param[in]     *infor 获取信息目标地址
* @param[out]    无
* @return        返回数据长度
* @attention     无
*******************************************************************************/
uint32_t vehicle_engine_start_st_get( uint8_t *infor )
{
	vehicle_engine_start_infor_t *engine_infor = NULL;
	
	engine_infor = ( vehicle_engine_start_infor_t *)infor;
	engine_infor->sn = REV_U16( vehicle_engine_start_infor.sn );
	engine_infor->id = REV_U16( vehicle_engine_start_infor.id );
	engine_infor->st = vehicle_engine_start_infor.st;

	return sizeof( vehicle_engine_start_infor_t );
}

/** ****************************************************************************
* @remarks       void vehicle_engine_start_st_clean( void )
* @brief         清除车辆一键启动控制数据
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
void vehicle_engine_start_st_clean( void )
{
	memset( (uint8_t *)&vehicle_engine_start_infor, 0x00, sizeof( vehicle_engine_start_infor_t ) );
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_engine_start_result_set( uint8_t *infor )
* @brief         设置车辆一键启动控制应答数据
* @param[in]     *infor 设置信息源地址
* @param[out]    无
* @return        pdPASS 成功，pdFAIL 失败
* @attention     无
*******************************************************************************/
uint32_t vehicle_engine_start_result_set( uint8_t *infor )
{
	uint32_t ret = pdFAIL;
	vehicle_engine_start_result_t *engine_infor = NULL;

	engine_infor = ( vehicle_engine_start_result_t *)infor;
	vehicle_engine_start_result.sn = REV_U16( engine_infor->sn );
	vehicle_engine_start_result.id = REV_U16( engine_infor->id );
	vehicle_engine_start_result.res = engine_infor->res;
	vehicle_engine_start_result.type = REV_U16( engine_infor->type );
	ret = pdPASS;
	
	return ret;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_engine_start_result_get( uint8_t *infor )
* @brief         获取车辆一键启动应答数据
* @param[in]     无
* @param[out]    *infor 获取信息目标地址
* @return        返回数据长度
* @attention     无
*******************************************************************************/
uint32_t vehicle_engine_start_result_get( uint8_t *infor )
{
	vehicle_engine_start_result_t *engine_infor = NULL;

	engine_infor = ( vehicle_engine_start_result_t *)infor;
	engine_infor->sn = REV_U16( vehicle_engine_start_result.sn );
	engine_infor->id = REV_U16( vehicle_engine_start_result.id );
	engine_infor->res = vehicle_engine_start_result.res;
	engine_infor->type = REV_U16( vehicle_engine_start_result.type );

	return sizeof( vehicle_engine_start_result_t );
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_fault_code_infor_set( uint8_t type, uint8_t model )
* @brief         查询车辆故障码信息
* @param[in]     type 故障码表类型，model 车辆类型，size 数据长度，*infor 数据源地址 
* @param[out]    无
* @return        pdPASS 成功，pdFAIL 失败
* @attention     无
*******************************************************************************/
uint32_t vehicle_fault_code_infor_set( uint8_t type, uint8_t model ,uint16_t size, uint8_t *infor )
{
	uint32_t ret = pdFAIL, i = 0, *code_infor = NULL;
	
	if(( size == 0x00 ) || ( infor == NULL ))
	{
		vehicle_fault_code_state = FAULE_CODE_INIT;
		vehicle_fault_code_infor.type = type;
		vehicle_fault_code_infor.model = model;
		vehicle_fault_code_infor.size = 0;
		memset( (uint8_t *)vehicle_fault_code_infor.dtc, 0x00, sizeof(uint32_t)*VEHICLE_DTC_INFOR_SIZE );
		ret = pdPASS;
	}
	else
	{
		if( size ==  ( VEHICLE_DTC_INFOR_SIZE * 4 ) )
		{
			vehicle_fault_code_state = FAULE_CODE_READ;
			code_infor = (uint32_t *)infor;
			vehicle_fault_code_infor.type = type;
			vehicle_fault_code_infor.model = model;
			vehicle_fault_code_infor.size = VEHICLE_DTC_INFOR_SIZE;
			for( i = 0; i < VEHICLE_DTC_INFOR_SIZE; i ++ )
			{
				vehicle_fault_code_infor.dtc[i] = REV_U32( code_infor[i] );
			}
			ret = pdPASS;
		}
	}
	
	return ret;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_fault_code_infor_get( uint8_t *infor )
* @brief         获取车辆故障码信息
* @param[in]     无
* @param[out]    *infor 故障信息目标地址
* @return        数据长度
* @attention     无
*******************************************************************************/
uint32_t vehicle_fault_code_infor_get( uint8_t *infor )
{
	#define OBU_DTC_LEN	( 15 )
	#define EMS_DTC_LEN	( 10 )
	#define TCU_DTC_LEN	( 10 )
	#define BMS_DTC_LEN	( 10 )
	uint16_t i = 0,size = 0,index = 0;
	
	if( vehicle_fault_code_infor.size != VEHICLE_DTC_INFOR_SIZE )
	{
		return 0;
	}
	/*数据组包*/
	infor[index++] = vehicle_fault_code_infor.type;
	infor[index++] = vehicle_fault_code_infor.model;
	/*获OBD 数据长度，以及数据内容*/
	size = 0;
	for( i = 0; i < OBU_DTC_LEN; i ++ )	
	{
		if( vehicle_fault_code_infor.dtc[0+i] != 0 )
		{
			size ++;
		}
	}
	u16toHex2( size,( uint8_t *)&infor[index] );
	index += 2;
	for( i = 0; i < size; i ++ )	
	{
		u32toHex4( vehicle_fault_code_infor.dtc[0+i], ( uint8_t *)&infor[index] );
		index += 4;
	}
	/*获取EMS 数据长度，以及数据内容*/
	size = 0;
	for( i = 0; i < EMS_DTC_LEN; i ++ )	
	{
		if( vehicle_fault_code_infor.dtc[OBU_DTC_LEN+i] != 0 )
		{
			size ++;
		}
	}
	u16toHex2( size,( uint8_t *)&infor[index] );
	index += 2;
	for( i = 0; i < size; i ++ )	
	{
		u32toHex4( vehicle_fault_code_infor.dtc[OBU_DTC_LEN+i], ( uint8_t *)&infor[index] );
		index += 4;
	}
	/*获取TCU 数据长度，以及数据内容*/
	size = 0;
	for( i = 0; i < TCU_DTC_LEN; i ++ )	
	{
		if( vehicle_fault_code_infor.dtc[OBU_DTC_LEN+EMS_DTC_LEN+i] != 0 )
		{
			size ++;
		}
	}
	u16toHex2( size,( uint8_t *)&infor[index] );
	index += 2;
	for( i = 0; i < size; i ++ )	
	{
		u32toHex4( vehicle_fault_code_infor.dtc[OBU_DTC_LEN+EMS_DTC_LEN+i], ( uint8_t *)&infor[index] );
		index += 4;
	}
	/*获取BMS 数据长度，以及数据内容*/
	size = 0;
	for( i = 0; i < BMS_DTC_LEN; i ++ )	
	{
		if( vehicle_fault_code_infor.dtc[OBU_DTC_LEN+EMS_DTC_LEN+TCU_DTC_LEN+i] != 0 )
		{
			size ++;
		}
	}
	u16toHex2( size,( uint8_t *)&infor[index] );
	index += 2;
	for( i = 0; i < size; i ++ )	
	{
		u32toHex4( vehicle_fault_code_infor.dtc[OBU_DTC_LEN+EMS_DTC_LEN+TCU_DTC_LEN+i], ( uint8_t *)&infor[index] );
		index += 4;
	}
	
	return index;
}

/** ****************************************************************************
* @remarks       static void print_save_mcu_data( void )
* @brief         打印存储的 MCU 信息
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void print_save_mcu_data( void )
{
	uint8_t vin[18];
	memset(vin,0,18);

	gaoz_log_debug_printf(INFOR_MODE,"mcar","print save mcu data:doors:%2x lights:%2x lock:%2x brake_gear:%2x  Ignition:%2x  speed:%d  bat_vol:%d 	Odo:%d  Oil:%d  Electricity:%d  Endurance_mileage:%d  relay_sta:%d \r\n",
																  vehicle_mcu_save_infor[0],
																  vehicle_mcu_save_infor[1],
																  vehicle_mcu_save_infor[3],
																  vehicle_mcu_save_infor[4],
																  vehicle_mcu_save_infor[5],
																  hex2CombineOne(&vehicle_mcu_save_infor[8]),
																  hex4CombineOne(&vehicle_mcu_save_infor[10]),
																  hex4CombineOne(&vehicle_mcu_save_infor[14]),
																  hex2CombineOne(&vehicle_mcu_save_infor[18]),
																  hex2CombineOne(&vehicle_mcu_save_infor[20]),
																  hex2CombineOne(&vehicle_mcu_save_infor[22]),
																  (vehicle_mcu_save_infor[24]&0x01)
																  );// 车门
 


	gaoz_log_debug_printf(INFOR_MODE,"mcar","prold save mcu data:doors:%2x lights:%2x lock:%2x brake_gear:%2x  Ignition:%2x  speed:%d  bat_vol:%d 	Odo:%d  Oil:%d  Electricity:%d  Endurance_mileage:%d  relay_sta:%d \r\n",
																  vehicle_mcu_save_infor_old[0],
																  vehicle_mcu_save_infor_old[1],
																  vehicle_mcu_save_infor_old[3],
																  vehicle_mcu_save_infor_old[4],
																  vehicle_mcu_save_infor_old[5],
																  hex2CombineOne(&vehicle_mcu_save_infor_old[8]),
																  hex4CombineOne(&vehicle_mcu_save_infor_old[10]),
																  hex4CombineOne(&vehicle_mcu_save_infor_old[14]),
																  hex2CombineOne(&vehicle_mcu_save_infor_old[18]),
																  hex2CombineOne(&vehicle_mcu_save_infor_old[20]),
																  hex2CombineOne(&vehicle_mcu_save_infor_old[22]),
																  (vehicle_mcu_save_infor_old[24]&0x01)
																  );// 车门


	memcpy(vin,vehicle_data.vin,17);
	gaoz_log_debug_printf(INFOR_MODE,"mcar","print save mcu data: VIN:%s \r\n",vin);	
	memcpy(vin,vehicle_data_old.vin,17);
 	gaoz_log_debug_printf(INFOR_MODE,"mcar","prold save mcu data: VIN:%s \r\n",vin); 
 
}

/** ****************************************************************************
* @remarks       static void vehicle_save_mcu_data_infor_init( void )
* @brief         初始化保存的MCU关键信息
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void vehicle_save_mcu_data_infor_init( void )
{  
	
	uint32_t tp_data = 0;
	/*读取MCU关键性数据*/
	uint16_t save_init_data_len = sizeof(vehicle_save_data_t);
	memset( (uint8_t *)&current_data,0x00,save_init_data_len);
	if(gaoz_save_vin_data_infor_read( (uint8_t *)&current_data, save_init_data_len ) == pdPASS )
	{   
		memcpy(vehicle_data.vin, current_data.vin, 17);
		vehicle_data.brake_gear = current_data.brake_gear;
		vehicle_data.Odo = current_data.Odo;
		vehicle_data.Oil = current_data.Oil;
		vehicle_data.Electricity = current_data.Electricity;
		vehicle_data.Endurance_mileage = current_data.Endurance_mileage;
		gaoz_log_debug_printf(INFOR_MODE,"mcar","init brake_gear%d, Odo%d, Oil:%d, Electricity%d, Endurance_mileage%d, VIN%s\n", current_data.brake_gear, current_data.Odo,current_data.Oil,current_data.Electricity,current_data.Endurance_mileage,current_data.vin);
	}

	print_save_mcu_data();
}

/** ****************************************************************************
* @remarks       static void vehicle_save_mcu_data_infor_send( void )
* @brief         MCU关键信息发送
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void vehicle_save_mcu_data_infor_send( void )
{
	uint8_t mcu_data_infor[100] = { 0 }, size = 0;
	
	mcu_data_infor[size++] = 0xEF;	/*状态字*/
	mcu_data_infor[size++] = 0;		/*数据长度*/
	mcu_data_infor[size++] = VEH_MCU_INFOR_SIZE;
	memcpy( (uint8_t *)&mcu_data_infor[size],(uint8_t *)vehicle_mcu_save_infor, VEH_MCU_INFOR_SIZE );
	size += VEH_MCU_INFOR_SIZE;

	memcpy((uint8_t *)&mcu_data_infor[size],vehicle_data.vin,17); 
	size += 17;

	gaoz_log_debug_printf(INFOR_MODE,"mcar","1017 save mcu data send suc\r\n",0);
	print_save_mcu_data();
	sendto_mcu_info(0x1017,(uint8_t *)TERM_ID,(uint8_t *)mcu_data_infor,size);
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_tire_pressure_data_get( void )
* @brief         获取车辆车胎压力
* @param[in]     无
* @param[out]    *infor 数据目标地址
* @return        数据长度
* @attention     无
*******************************************************************************/
uint32_t vehicle_tire_pressure_data_get( uint8_t *infor )
{
	infor[0] = vehicle_data.TPMSRst;	//胎压标志是否有效
	infor[1] = vehicle_data.lf_TP;		//左前轮胎压值
	infor[2] = vehicle_data.rf_TP;		//右前轮胎压值
	infor[3] = vehicle_data.lr_TP;		//左后轮胎压值
	infor[4] = vehicle_data.rr_TP;		//右后轮胎压值
	
	infor[5] = vehicle_data.lf_T;		//左前轮胎温度
	infor[6] = vehicle_data.rf_T;		//右前轮胎温度
	infor[7] = vehicle_data.lr_T;		//左后轮胎温度
	infor[8] = vehicle_data.rr_T;		//右后轮胎温度
	infor[9] = 0x00;					//预留字节
	
	return 10;
}

/** ****************************************************************************
* @remarks       uint8_t vehicle_type_data_get( void )
* @brief         获取车辆类型数据
* @param[in]     无
* @param[out]    无
* @return        车辆类型 0-电车 1-油车
* @attention     无
*******************************************************************************/
uint8_t vehicle_type_data_get( void )
{
	if(( vehicle_data.vehicle_type & 0x01 ) == 0x01 )
	{
		return 0x01;
	}

	return 0x00;
}

/** ****************************************************************************
* @remarks       uint8_t vehicle_type_sensor_get( void )
* @brief         获取氧气传感器状态
* @param[in]     无
* @param[out]    无
* @return        车辆类型 0-正常 1-报警
* @attention     神州项目中使用
*******************************************************************************/
uint8_t vehicle_type_sensor_get( void )
{
	if(( vehicle_data.vehicle_type & 0x02 ) == 0x02 )
	{
		return 0x1;
	}

	return 0x00;
}


/** ****************************************************************************
* @remarks       uint32_t vehicle_maintenance_infor_set( uint8_t *infor, uint32 size )
* @brief         设置车辆保养数据
* @param[in]     无
* @param[out]    无
* @return        pdPASS - 成功，pdFAIL - 失败
* @attention     无
*******************************************************************************/
uint32_t vehicle_maintenance_infor_set( uint8_t *infor, uint32 size )
{
	vehicle_maintenance_infor_t *main_infor = NULL;

	if( ( sizeof( vehicle_maintenance_infor_t ) ) != size )
	{
		return pdFAIL;
	}

	main_infor = ( vehicle_maintenance_infor_t *)infor;
	vehicle_maintenance_infor.mileage = REV_U32( main_infor->mileage );
	vehicle_maintenance_infor.time = REV_U16( main_infor->time );
	vehicle_maintenance_infor.smail_mil = REV_U32( main_infor->smail_mil );
	vehicle_maintenance_infor.smail_time = REV_U16( main_infor->smail_time );
	vehicle_maintenance_infor.oil_per = main_infor->oil_per;
	
	return pdPASS;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_maintenance_infor_set( uint8_t *infor )
* @brief         获取车辆保养数据
* @param[in]     无
* @param[out]    *infor 数据源目标地址
* @return        获取得数据长度
* @attention     无
*******************************************************************************/
uint32_t vehicle_maintenance_infor_get( uint8_t *infor )
{
	vehicle_maintenance_infor_t *main_infor = NULL;
	rtc_struct location_Time = { 0 };
	/*组包RTC时间，保养信息主要使用年 月 日*/
	gaoz_rtc_sys_get(RTC_TIM_CAL_BCD,&location_Time);
	infor[0] = ( uint8_t )(location_Time.year&0xff);
	infor[1] = location_Time.month;
	infor[2] = location_Time.day;
	infor[3] = location_Time.hour;
	infor[4] = location_Time.minute;
	infor[5] = location_Time.second;
	/*组包保养信息*/
	main_infor = (vehicle_maintenance_infor_t *)&infor[6];
	main_infor->mileage = REV_U32( vehicle_maintenance_infor.mileage );
	main_infor->time = REV_U16( vehicle_maintenance_infor.time );
	main_infor->smail_mil = REV_U32( vehicle_maintenance_infor.smail_mil );
	main_infor->smail_time = REV_U16( vehicle_maintenance_infor.smail_time );
	main_infor->oil_per = vehicle_maintenance_infor.oil_per;
	
	return ( sizeof( vehicle_maintenance_infor_t ) + 6 );
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_maintenance_cfg_set( uint8_t *cfg, uint32 len )
* @brief         车辆保养信息设置
* @param[in]     无
* @param[out]    *infor 数据源目标地址
* @return        获取得数据长度
* @attention     无
*******************************************************************************/
uint32_t vehicle_maintenance_cfg_set( uint8_t *cfg, uint32 len )
{
	vehicle_maintenance_infor_t *main_infor = NULL;

	if( sizeof( vehicle_maintenance_infor_t ) != len )
	{
		return pdFAIL;
	}

	main_infor = ( vehicle_maintenance_infor_t *)cfg;
	vehicle_maintenance_cfg.state = 0x01;
	vehicle_maintenance_cfg.infor.mileage = REV_U32( main_infor->mileage );
	vehicle_maintenance_cfg.infor.time = REV_U16( main_infor->time );
	vehicle_maintenance_cfg.infor.smail_mil = REV_U32( main_infor->smail_mil );
	vehicle_maintenance_cfg.infor.smail_time = REV_U16( main_infor->smail_time );
	vehicle_maintenance_cfg.infor.oil_per = main_infor->oil_per;
	
	return pdPASS;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_maintenance_cfg_set( uint8_t *cfg, uint32 len )
* @brief         车辆保养信息设置
* @param[in]     无
* @param[out]    *infor 数据源目标地址
* @return        获取得数据长度
* @attention     无
*******************************************************************************/
uint32_t vehicle_maintenance_cfg_get( uint8_t *cfg )
{
	uint32_t ret = 0;
	vehicle_maintenance_infor_t *main_infor = NULL;

	if( cfg == NULL )
	{
		if( vehicle_maintenance_cfg.state == 0x01 )
		{
			ret = vehicle_maintenance_cfg.state;
		}
	}
	else
	{
		main_infor = (vehicle_maintenance_infor_t *)cfg;
		main_infor->mileage = REV_U32( vehicle_maintenance_cfg.infor.mileage );
		main_infor->time = REV_U16( vehicle_maintenance_cfg.infor.time );
		main_infor->smail_mil = REV_U32( vehicle_maintenance_cfg.infor.smail_mil );
		main_infor->smail_time = REV_U16( vehicle_maintenance_cfg.infor.smail_time );
		main_infor->oil_per = vehicle_maintenance_cfg.infor.oil_per;
		ret = sizeof( vehicle_maintenance_infor_t );
	}
	
	return ret;
}

/** ****************************************************************************
* @remarks       void vehicle_maintenance_cfg_state_clean( void )
* @brief         车辆保养状态信息清除
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
void vehicle_maintenance_cfg_state_clean( void )
{
	vehicle_maintenance_cfg.state = 0;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_bms_infor_set( uint8_t *infor, uint32 len )
* @brief         车辆BMS数据设置
* @param[in]     *infor 数据源地址，len 数据长度
* @param[out]    无
* @return        pdPASS - 成功，pdFAIL - 失败
* @attention     无
*******************************************************************************/
uint32_t vehicle_bms_infor_set( uint8_t *infor, uint32 len )
{
	uint32_t timeStamp;
	if( len != VEH_BMS_INFOR_LEN )
	{
		return pdFAIL;
	}
	vehicle_bms_infor.type = 0x14;

	gaoz_rtc_sys_get(RTC_TIM_TIMESTAMP,&timeStamp);
	  
	vehicle_bms_infor.data[VEH_BMS_INFOR_LEN-4] = (timeStamp>>24) & 0xFF;
	vehicle_bms_infor.data[VEH_BMS_INFOR_LEN-3] = (timeStamp>>16) & 0xFF;
	vehicle_bms_infor.data[VEH_BMS_INFOR_LEN-2] = (timeStamp>>8) & 0xFF;
	vehicle_bms_infor.data[VEH_BMS_INFOR_LEN-1] = (timeStamp) & 0xFF;
	 	  
	vehicle_bms_infor.len = VEH_BMS_INFOR_LEN;
	memcpy( (uint8_t *)&vehicle_bms_infor.data, (uint8_t *)infor, (VEH_BMS_INFOR_LEN-4));

	warmcar_bms_semaphore_put();
	
	return pdPASS;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_bms_infor_get( uint8_t *infor )
* @brief         获取车辆BMS数据
* @param[in]     无
* @param[out]    *infor 数据目标地址
* @return        数据包长度
* @attention     无
*******************************************************************************/
uint32_t vehicle_bms_infor_get( uint8_t *infor )
{
	uint32_t ret = 0;
	vehicle_bms_infor_t *bms= NULL;

	if( infor == NULL )
	{
		return 0;
	}
	if(( vehicle_bms_infor.type == 0x14 ) && ( vehicle_bms_infor.len == VEH_BMS_INFOR_LEN ))
	{
		bms = (vehicle_bms_infor_t *)infor;
		bms->type = vehicle_bms_infor.type;
		bms->len = REV_U16( vehicle_bms_infor.len );
		memcpy( (uint8_t *)bms->data, (uint8_t *)vehicle_bms_infor.data, VEH_BMS_INFOR_LEN );
		ret = sizeof( vehicle_bms_infor_t );
	}

	return ret;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_seed_infor_set( uint8_t *infor )
* @brief         设置SEED数据
* @param[in]     *infor 数据源地址
* @param[out]    无
* @return        pdFAIL-失败，pdPASS-成功
* @attention     无
*******************************************************************************/
uint32_t vehicle_seed_infor_set( uint8_t *infor )
{
	uint32_t ret = pdFAIL, packet_num = 0;
	vehicle_seed_infor_t *seed = NULL;
	uint8_t seed_safe_key[16] = { 0xBA,0xC3,0xC8,0xCB,0xBA,0xC3,0xB3,0xB5,0xB0,0xB2,0xC8,0xAB,0xC3,0xDC,0xD4,0xBF };
	
	if( vehicle_seed_infor.type == 0 )
	{
		seed = ( vehicle_seed_infor_t * )infor;
		vehicle_seed_infor.type  = REV_U16( seed->type ); 		/*获取车辆类型*/
		if( seed->len < VEH_SEED_KEY_INFOR_LEN - 1)				/*去掉数据包长度*/
		{
			memset( (uint8_t *)vehicle_seed_infor.data, 0x00, VEH_SEED_KEY_INFOR_LEN );
			packet_num = seed->len / 16;						/*计算整包数*/
			if( ( seed->len % 16 ) != 0 )
			{
				packet_num ++;
			}
			vehicle_seed_infor.data[0] = seed->len;				/*数据长度*/
			memcpy( (uint8_t*)&vehicle_seed_infor.data[1], (uint8_t *)seed->data, seed->len );
			aes_encrypt_multi( (uint8_t *)vehicle_seed_infor.data, 16 * packet_num, seed_safe_key );	/*数据加密*/
			vehicle_seed_infor.len = 16 * packet_num;
			ret = pdPASS;
		}
	}
	
	return ret;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_seed_infor_get( uint8_t *infor )
* @brief         获取SEED数据
* @param[in]     无
* @param[out]    *infor 数据目标地址
* @return        数据长度
* @attention     无
*******************************************************************************/
uint32_t vehicle_seed_infor_get( uint8_t *infor )
{	
	uint32_t ret = 0;
	vehicle_seed_infor_t *seed = NULL;
	
	if( vehicle_seed_infor.type != 0x00 )
	{	
		seed = ( vehicle_seed_infor_t * )infor;
		seed->type =  REV_U16( vehicle_seed_infor.type ); 
		seed->len = vehicle_seed_infor.len;
		if( vehicle_seed_infor.len < VEH_SEED_KEY_INFOR_LEN )
		{
			memcpy( (uint8_t *)seed->data, ( uint8_t *)vehicle_seed_infor.data, vehicle_seed_infor.len );
			ret = 3 + vehicle_seed_infor.len;
		}
		/*数据读取完成后清空SEED缓存中的数据*/
		memset( (uint8_t *)&vehicle_seed_infor, 0x00, sizeof( vehicle_seed_infor ));
	}

	return ret;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_key_infor_set( uint8_t *infor )
* @brief         设置KEY数据
* @param[in]     *infor 数据源地址
* @param[out]    无
* @return        pdFAIL-失败，pdPASS-成功
* @attention     无
*******************************************************************************/
uint32_t vehicle_key_infor_set( uint8_t *infor )
{
	uint32_t ret = pdFAIL;
	vehicle_key_infor_t *key = NULL;
	uint8_t key_safe_key[16] = { 0xBA,0xC3,0xC8,0xCB,0xBA,0xC3,0xB3,0xB5,0xB0,0xB2,0xC8,0xAB,0xC3,0xDC,0xD4,0xBF };
	uint8_t decrypt_buf[64] = { 0 };
	
	if( infor == NULL )
	{
		return pdFAIL;
	}
	key = ( vehicle_key_infor_t * )infor;
	if( key->len < VEH_SEED_KEY_INFOR_LEN )
	{
		if( ( key->len != 0) && (( key->len % 16 ) == 0) )
		{
			memcpy( (uint8_t *)decrypt_buf, ( uint8_t *)key->data, key->len );
			aes_decrypt_multi( decrypt_buf, key->len, key_safe_key );
			vehicle_key_infor.len = decrypt_buf[0];
			memcpy( (uint8_t *)vehicle_key_infor.data, (uint8_t *)&decrypt_buf[1], vehicle_key_infor.len );
		}
		ret = pdPASS;
	}
	
	return ret;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_key_infor_get( uint8_t *infor )
* @brief         获取KEY数据
* @param[in]     无
* @param[out]    *infor 目标地址
* @return        数据长度
* @attention     无
*******************************************************************************/
uint32_t vehicle_key_infor_get( uint8_t *infor )
{
	uint32_t ret = 0;
	vehicle_key_infor_t *key = NULL;

	key = ( vehicle_key_infor_t * )infor;
	key->len = vehicle_key_infor.len;
	if( vehicle_key_infor.len < VEH_SEED_KEY_INFOR_LEN )
	{
		if( vehicle_key_infor.len != 0)
		{
			memcpy( (uint8_t *)key->data, (uint8_t *)vehicle_key_infor.data, vehicle_key_infor.len );
		}
		ret = 1 + vehicle_key_infor.len;
	}
	
	return ret;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_adas_infor_set( uint8_t *infor )
* @brief         设置车辆ADAS实时数据包
* @param[in]     *infor 数据源地址
* @param[out]    无
* @return        pdFAIL - 失败，pdPASS - 成功。
* @attention     无
*******************************************************************************/
uint32_t vehicle_adas_infor_set( uint8_t *infor )
{
	uint32_t ret = pdFAIL , i = 0, timeStamp = 0;
#if 0
	uint8_t  time_ms = 0, time_counter = 0, position = 0;
#else
	uint8_t position = 0;
#endif
	
	if( infor == NULL )
	{
		return pdFAIL;
	}
	if(( infor[0] > 0 ) && ( infor[0] <= VEH_ADAS_INFOR_NUM ))
	{
		vehicle_adas_infor.total = infor[0];
		gaoz_rtc_sys_get( RTC_TIM_TIMESTAMP, (uint32_t *)&timeStamp );
	#if 0
		if( vehicle_adas_infor.total / 5 )
		time_counter = vehicle_adas_infor.total / 5;
		if(( vehicle_adas_infor.total % 5 ) != 0 )
		{
			time_counter ++;
		}
		timeStamp = timeStamp - time_counter;
	#else
		timeStamp = timeStamp - vehicle_adas_infor.total;
	#endif
		for( i = 0; i < vehicle_adas_infor.total; i ++ )
		{
			vehicle_adas_infor.data[i].timestamp = timeStamp;
		#if 0
			vehicle_adas_infor.data[i].ms = 2 * time_ms ++;
		#else
			vehicle_adas_infor.data[i].ms = 0;
		#endif
			vehicle_adas_infor.data[i].speed =  infor[i*6 + 1] *256 +  infor[i*6 + 2];			
			vehicle_adas_infor.data[i].oil_pos = infor[i*6 + 3];
			vehicle_adas_infor.data[i].brake_pos = infor[i*6 + 4];
			vehicle_adas_infor.data[i].wheel_angle = infor[i*6 + 5] *256 +  infor[i*6 + 6];
			vehicle_adas_infor.data[i].lat = vehicle_adas_position[position].lat;	
			vehicle_adas_infor.data[i].lon = vehicle_adas_position[position].lon;
		#if 0
			if( time_ms == 5 )
			{
				timeStamp ++;
				position ++;
				time_ms = 0;
			}
		#else
			timeStamp ++;
			position ++;
		#endif
		}
		ret = pdPASS;
	}
	
	return ret;
}

/** ****************************************************************************
* @remarks       uint32_t vehicle_adas_infor_get( uint8_t *infor )
* @brief         获取车辆ADAS实时数据包
* @param[in]     无
* @param[out]    *infor 目标地址
* @return        数据长度
* @attention     无
*******************************************************************************/
uint32_t vehicle_adas_infor_get( uint8_t *infor )
{
	uint32_t size = 0, i = 0;
	vehicle_adas_data_t *adas_data = NULL;

	if(( infor == NULL ) || ( vehicle_adas_infor.total == 0 ))
	{
		return 0;
	}
	infor[0] = vehicle_adas_infor.total;
	size += 1;
	for( i = 0; i < vehicle_adas_infor.total; i ++ )
	{
		adas_data = ( vehicle_adas_data_t * )&infor[ size ];
		adas_data->timestamp = REV_U32( vehicle_adas_infor.data[i].timestamp );	
		adas_data->ms = vehicle_adas_infor.data[i].ms; 
		adas_data->speed = REV_U16( vehicle_adas_infor.data[i].speed );	
		adas_data->oil_pos = vehicle_adas_infor.data[i].oil_pos;
		adas_data->brake_pos = vehicle_adas_infor.data[i].brake_pos;
		adas_data->wheel_angle = REV_U16( vehicle_adas_infor.data[i].wheel_angle );	
		adas_data->lat = REV_U32( vehicle_adas_infor.data[i].lat );
		adas_data->lon = REV_U32( vehicle_adas_infor.data[i].lon );
		size += sizeof( vehicle_adas_data_t );
	}
	
	return size;
}

/** ****************************************************************************
* @remarks       void vehicle_adas_position_read( void )
* @brief         获取车辆ADAS实时定位数据
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void vehicle_adas_position_read( void )
{
	static uint8_t pos_once_read = 0;
	uint8_t i = 0;
	gnss_info_struct gnss_info = { 0 };

	if( pos_once_read == 0 )		/*系统第一次启动时将所以的经纬度进行刷新*/
	{
		pos_once_read = 1;
		gaoz_gnss_info_now_get( &gnss_info );
		for( i = 0; i < VEH_ADAS_POSION_NUM; i ++ )
		{
			vehicle_adas_position[i].lat = gnss_info.gnss_position_info.latitude;	
			vehicle_adas_position[i].lon = gnss_info.gnss_position_info.longitude;
		}
	}
	else
	{								
		gaoz_gnss_info_now_get( &gnss_info );
		for( i = 0; i < (VEH_ADAS_POSION_NUM - 1); i ++ )
		{  
			vehicle_adas_position[i].lat = vehicle_adas_position[i+1].lat;
			vehicle_adas_position[i].lon = vehicle_adas_position[i+1].lon;
		}
		vehicle_adas_position[VEH_ADAS_POSION_NUM - 1].lat = gnss_info.gnss_position_info.latitude;	
		vehicle_adas_position[VEH_ADAS_POSION_NUM - 1].lon = gnss_info.gnss_position_info.longitude;
	}
}


/** ****************************************************************************
* @remarks       void vehicle_rv_power_control_set( uint8_t control )
* @brief         控制房车电源
* @param[in]     control 控制01-启动，02-熄火
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
void vehicle_rv_power_control_set( uint8_t control )
{
	vehicle_rv_power_control = control;
}

/** ****************************************************************************
* @remarks       void vehicle_authentication_time_detection( void )
* @brief         周期性发送鉴权信息
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void vehicle_authentication_time_detection( void )
{
#if( OS_HALUO_PROJECT_ENABLE == 1 )
	#define AUTH_TIMESTAMP_INTERVAL ( 14400 )	/*4小时 14400S 哈啰项目要求*/
#else
	#define AUTH_TIMESTAMP_INTERVAL ( 43200 )	/*12小时 43200S*/
#endif
	
	static uint32_t auth_timestamp_current = 0;
	static uint32_t auth_timestamp_history = 0;
	
	if( auth_timestamp_history == 0 )
	{
		gaoz_rtc_sys_get( RTC_TIM_TIMESTAMP, (uint32_t *)&auth_timestamp_history );
	}
	gaoz_rtc_sys_get( RTC_TIM_TIMESTAMP, (uint32_t *)&auth_timestamp_current );
	if( auth_timestamp_current >= auth_timestamp_history )
	{
		if( ( auth_timestamp_current - auth_timestamp_history ) >= AUTH_TIMESTAMP_INTERVAL )
		{
			// if( vehicle_authentication_st_get() != VEHICLE_AUTH_REQ )
			// {
			// 	vehicle_authentication_st_set( VEHICLE_AUTH_REQ );
			// }
			if( vehicle_authentication_mangatio_st_get() != VEHICLE_AUTH_REQ )
			{
				vehicle_authentication_mangatio_st_set( VEHICLE_AUTH_REQ );
			}
			national808_auth_reason_set(NET_AUTH_REASON_PERIODIC); 
			national808_net_ctrl_infor_set( TER_RUNING_AUTH );
			gaoz_rtc_sys_get( RTC_TIM_TIMESTAMP, (uint32_t *)&auth_timestamp_history );
		}
	}
}

/** ****************************************************************************
* @remarks       void vehicle_create_task( unsigned portBASE_TYPE uxPriority )
* @brief         创建车机数据处理任务
* @param[in]     uxPriority 优先级
* @param[out]    无
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
void vehicle_create_task( unsigned portBASE_TYPE uxPriority )
{
	int ret = 0;

	vehicle_ota_sem_create();
	vehicle_data_mutex = gaoz_mutex_create();
    if( vehicle_data_mutex == 0 )
    {
        while(1); /*创建失败*/
    }
    mcu_recv_data_mutex_create();
    mcu_recv_data.data = (uint8_t *)gaoz_fibo_malloc( N808MCU_RX_BUF_SIZE );
    if(mcu_recv_data.data == NULL)
    {
        while(1); /*创建失败*/
    }
    memset((uint8_t *)mcu_recv_data.data, 0x00 , N808MCU_RX_BUF_SIZE);
    mcu_recv_data.len = 0;

	memset( (uint8_t *)&vehicle_warmcar_package, 0x00, sizeof( vehicle_warmcar_package_data_t ) );
	memset( (uint8_t *)&vehicle_warmcar_led_data, 0x00, sizeof( vehicle_warmcar_led_data_t ) );
	memset( (uint8_t *)&vehicle_warmcar_net_data, 0x00, sizeof( vehicle_warmcar_net_data_t ) );
	
	vehicle_authentication_st = VEHICLE_AUTH_INIT;
	memset( (uint8_t *)&vehicle_engine_start_infor, 0x00, sizeof( vehicle_engine_start_infor_t ) );
	memset( (uint8_t *)&vehicle_engine_start_result, 0x00, sizeof( vehicle_engine_start_result_t ) );
	vehicle_fault_code_state = FAULE_CODE_INIT;
	memset( (uint8_t *)&vehicle_fault_code_infor, 0x00, sizeof( vehicle_fault_code_infor_t ) );
	memset( (uint8_t *)&vehicle_maintenance_infor, 0x00, sizeof( vehicle_maintenance_infor_t ) );
	memset( (uint8_t *)&vehicle_maintenance_cfg, 0x00, sizeof( vehicle_maintenance_cfg_t ) );
	/*车辆安全密钥数据结构体初始化*/
	memset( (uint8_t *)&vehicle_seed_infor, 0x00, sizeof( vehicle_seed_infor_t ) );
	memset( (uint8_t *)&vehicle_key_infor, 0x00, sizeof( vehicle_key_infor_t ) );
	/*车辆ADAS实时数据结构体初始化*/
	memset( (uint8_t *)&vehicle_adas_infor, 0x00,sizeof( vehicle_adas_infor_t ));
	vehicle_rv_power_control = 0;

	/*系统上电时读取MCU存储的关键信息*/
	vehicle_save_mcu_data_infor_init();
    /* mcu_uart_driver */
    ret = gaoz_mcu_uart_driver_open(parse_mcu_recv_data,mcu_recv_state_cb);
    if(ret == pdPASS)
    {
        gaoz_log_debug_printf(INFOR_MODE,"mcar","gaoz_mcu_uart_driver_open ok[]\n");
    }
    /* save_data */
	ret = gaoz_save_data_open( &sfb_handle_808 ,&sfb_set_808 ,&sfb_handle_id );
	if( ret == pdPASS )
	{
		gaoz_log_debug_printf(INFOR_MODE,"mcar","gaoz_save_data_open ok[%d]\n", sfb_handle_id);
	}
    else
    {
        while(1);
    }
	/*设置三轴加速度传感器回调入口函数地址*/
	gsen_sensor_state_cb_set(n808_gsen_sensor_state_cb);
	/*测试验证用暂时屏蔽*/
	// gaoz_save_data_close(sfb_handle_id);
	// ret = gaoz_save_data_open( &sfb_handle_808 ,&sfb_set_808 ,&sfb_handle_id );
	// if( ret == pdPASS )
	// {
	// 	gaoz_log_debug_printf(INFOR_MODE,"mcar","gaoz_save_data_open ok[%d]\n", sfb_handle_id);
	// }
    // else
    // {
    //     while(1);
    // }
    gaoz_thread_create(vehicle_data_handle_task, VEH_MAN_NAME, 1024*5, NULL, uxPriority);
	gaoz_thread_create(vehicle_ctrl_handle_task, VEH_CTRL_NAME, 1024*5, NULL, uxPriority);
	gaoz_thread_create(vehicle_ota_handle_task, VEH_OTA_NAME, 1024*5, NULL, uxPriority);
	
}


